Google 通过 Google 脚本和网络界面执行的查询公式给出了不同的结果

Google query formula executed via Google Script and web interface gives different results

我需要一个解决方案来解决我的问题,即如何在 Google 脚本中获取 today and tomorrow 的日期。我在 While trying to understand the code provided in the answer I found out that I get different result from the script and from web interface. The script does not pick up one email, the one that was sent 0:49am. 中得到它 请注意,脚本有 6 个线程,但 Web 界面有 7 个。

知道该怎么办吗?调试,报告?

function today_tmp() {
  const today = new Date();
  const today_2 = new Date();
  today_2.setDate(new Date().getDate()+1);
  const td = Utilities.formatDate(today, 'GMT+2', "yyyy/MM/dd");
  const td_2 = Utilities.formatDate(today_2, 'GMT+2', "yyyy/MM/dd");
  const mylabel = 'unread';
  const queryString = `label: ${mylabel} after: ${td} before: ${td_2}`;
  const threads = GmailApp.search(queryString); 
  //const threads =GmailApp.search(queryString, 0, 10);  // this one did not work
  Logger.log(queryString);
  Logger.log(threads.length);
  for (var t in threads) {
    Logger.log(threads[t].getMessages()[0].getSubject());    
  }
}

更新 GMT+1 在项目属性中设置。我试图在代码中更改 GMT+1,但它对问题没有影响。我住在布拉格时区。

getDate()“丢失”消息是 Wed Oct 21 00:49:09 GMT+02:00 2020,今天是 10 月 21 日。

经过反复试验,仅按日期搜索时,GmailApp.search 似乎与时区信息不一致(脚本项目属性与 GmailApp API 命令)。如果您需要根据您的时区非常具体地捕获日期边界,您应该将该信息作为时间戳值传递。

const mylabel = 'unread';
const morning = new Date();
morning.setHours(0, 0, 0, 0);  // Set date to midnight of current day
const night = new Date();
night.setHours(24, 0, 0, 0); // Set end date to future midnight of current day

const queryString = `label: ${mylabel} newer:${morning.getTime()/1000} older:${night.getTime()/1000}`;
const threads = GmailApp.search(queryString);