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
}
添加回答
举报