Errors with Utilties.FormatDate

2019-07-26 23:47发布

In a Google Apps script I am using to create leave request approvals I am using the following text to return the appropriate time in an email generated by the script.

Utilities.formatDate(new Date(row.timeToLeaveSchool), "CST", "h:mm aa")

It was working well until today it was pointed out to me that the returned time is showing GMT instead of CST. I've tried GMT-6 instead of CST and also just altering the timezone to see if it impacted the script.

Both the script and spreadsheet attached are set for CST.

Any help would be appreciated.

1条回答
Bombasti
2楼-- · 2019-07-27 00:33

Try using Utilities.formatDate(new Date(), "GMT-06:00", "h:mm aa")

According to this page:

For compatibility with JDK 1.1.x, some other three-letter time zone IDs (such as "PST", "CTT", "AST") are also supported. However, their use is deprecated because the same abbreviation is often used for multiple time zones (for example, "CST" could be U.S. "Central Standard Time" and "China Standard Time"), and the Java platform can then only recognize one of them.

So, CST probably doesn't work for this reason. And to clarify, "GMT-6" does not work but "GMT-06:00" does work.

查看更多
登录 后发表回答