为什么 Apps Script Session.getScriptTimeZone() 的时区偏移量与项目属性中的时区偏移量不同一小时?

Why is the Time Zone offset of Apps Script Session.getScriptTimeZone() one hour different than in the project properties?

在 Apps 脚本中,项目文件有自己的时区设置:

在这种情况下,时区偏移量是负 5。但是当我的代码记录脚本时区时,它是负 4!关闭一小时。如何修复我的代码以获得正确的时区偏移量?

代码如下:

function getTimezoneOffset(){
  var testMonth = "March",
      testDayOfMnth = "26",
      testYr = "2016";

  var hour = "10:00";

  Logger.log("Script Time Zone: " + Session.getScriptTimeZone());

  var dateString = testMonth + " " + testDayOfMnth + ", " + testYr;
  Logger.log("dateString: " + dateString);

  var date = new Date(dateString);

  var scrptTimeZone = Session.getScriptTimeZone();
  Logger.log("Session.getScriptTimeZone(): " + Session.getScriptTimeZone());

  var scriptTimeZone = Utilities.formatDate(date, scrptTimeZone, 'Z');
  Logger.log("scriptTimeZone: " + scriptTimeZone);
};

日志打印出来

是的,是夏令时(3 月 13 日)。 试试这个:

var date1 = new Date("March 12, 2016 10:00");  // EST – Eastern Standard Time
Logger.log("dateString: " + date1);
// result: dateString: Sat Mar 12 2016 10:00:00 GMT-0500 (EST)


var date2 = new Date("March 13, 2016 10:00");  // EDT – Eastern Daylight Time
Logger.log("dateString: " + date2);
// result: dateString: Sun Mar 13 2016 10:00:00 GMT-0400 (EDT)