1 回答

TA貢獻1878條經驗 獲得超4個贊
解釋:
正如Cooper所建議的那樣,您可以使用Utilities類構造日期并將它們轉換為所需的格式。
然后,您可以使用模板文字構造查詢參數并將所有日期和標簽變量傳遞給字符串對象。
getSpreadsheetTimeZone()用于獲取電子表格的時區。您可以將其替換為實際的
GMT
,例如:const?td?=?Utilities.formatDate(today,?'GMT+1',?"yyyy/MM/dd"); const?td_2?=?Utilities.formatDate(today_2,?'GMT+1',?"yyyy/MM/dd");
使用電子表格時區的解決方案:
function myFunction() {
? const ss = SpreadsheetApp.getActive();
? const today = new Date();
? const today_2 = new Date();
? today_2.setDate(new Date().getDate()+2);
? const td = Utilities.formatDate(today, ss.getSpreadsheetTimeZone(), "yyyy/MM/dd");
? const td_2 = Utilities.formatDate(today_2, ss.getSpreadsheetTimeZone(), "yyyy/MM/dd");
? const mylabel = 'unread';
??
? const queryString = `label: ${mylabel} after: ${td} before: ${td_2}`;
? const threads = GmailApp.search(queryString);?
}
自定義時區的解決方案:
調整GMT+1到您自己/想要的時區。
function myFunction() {
??
? const today = new Date();
? const today_2 = new Date();
? today_2.setDate(new Date().getDate()+2);
? const td = Utilities.formatDate(today, 'GMT+1', "yyyy/MM/dd");
? const td_2 = Utilities.formatDate(today_2, 'GMT+1', "yyyy/MM/dd");
? const mylabel = 'unread';
??
? const queryString = `label: ${mylabel} after: ${td} before: ${td_2}`;
? Logger.log(queryString); // check the output in the View -> Logs
? const threads = GmailApp.search(queryString); // GmailThread[] — an array of Gmail threads matching this query
}
添加回答
舉報