早上好,我正在使用下面有人在网上精心提供的代码,每晚创建“备份”或谷歌表格的副本。问题是时间戳是 GMT,而我确实需要它是 EST(纽约)。有人可以告诉我如何解决这个问题吗?我完全是新手
原始链接:https://gist.github.com/abhijeechopra/99a11fb6016a70287112
问题领域: 生成时间戳并以变量 formattedDate 形式存储为年-月-日时-分-秒 var formattedDate = Utilities.formatDate(new Date(), "GMT", "yyyy-MM-dd' 'HH:mm:ss");
我累了打字EST,打字-5:00,时间不正确。
您的方向是正确的,输入“EST”或“-5:00”没有执行任何操作,因为它们不是
Utilities.formatDate()
正在寻找的格式。
这应该可以实现你所追求的目标:
Utilities.formatDate(new Date(), "US/Eastern", "yyyy-MM-dd' 'HH:mm:ss");
或
Utilities.formatDate(new Date(), "America/New_York", "yyyy-MM-dd' 'HH:mm:ss");
请注意,
"GMT"
最初是有效的,因为它在格式页面上被列为别名,但 EST 不是。