Google App脚本夏令时不正确

问题描述 投票:0回答:1

我有一个Google App脚本,每当触发某个事件时,该脚本就会向我发送一封电子邮件。该脚本运行良好,但是今天,它不再发送带有正确主题的电子邮件。我住在新西兰,今天恰好是我们的夏令时过渡。此处的时区为GMT + 12。我认为问题在于即使已将Google App Script配置为使用夏令时,也没有使用夏令时。

这是生成电子邮件主题的脚本的主要部分:

var date = Utilities.formatDate(new Date(), "GMT+12","dd-MM-yyyy' ----------- 'EEEE' ----------- 'hh:mm a' ----------- 'ss:SS' seconds ----------- 'Z' '");

电子邮件主题的输出如下所示:

enter image description here

您可以看到,时区是正确的,但时间不是。时间应该是07:12 PM。

在脚本/项目中,时区设置为正确的时区。我不确定为什么输出不正确?

date datetime google-apps-script dst
1个回答
2
投票

没关系,已经解决了这个问题。尽管在Google和StackOverFlow上找到了多个建议使用GMT + 12的答案,但我最终还是只使用了此方法:

var date = Utilities.formatDate(new Date(),"Pacific/Auckland","dd-MM-yyyy' ----------- 'EEEE' ----------- 'hh:mm a' ----------- 'ss:SS' seconds ----------- 'Z' '");
© www.soinside.com 2019 - 2024. All rights reserved.