问题描述
我有一个存储日期如下:
existingDate = Wed Apr 30 2014 00:00:00 GMT + 0100( BST)
当我使用 Utilities.formatDate 以格式化日期更改为前一天的日期。
var formattedDate = Utilities.formatDate(new Date(existingDate), GMT,dd / MM / yyyy);
然后将格式化的日期设置为 29/04/2014 和不是 30/04/2014 。
是否有其他人看到这种行为。
Utilities.formatDate 似乎工作正常。 您在 GMT-1 中有4月30日午夜,但您可以告诉它在不同的时区格式化此日期 GMT ,或更多的明确GMT-0。预期的结果确实是4月29日23h。
必须是您想要的时区。
I have a date stored as follows:
existingDate = Wed Apr 30 2014 00:00:00 GMT+0100 (BST)
When I use Utilities.formatDate to format the date the date is changed to the day before.
var formattedDate = Utilities.formatDate(new Date(existingDate), "GMT", "dd/MM/yyyy");
the formatted date is then set to 29/04/2014 and not 30/04/2014.
Has anyone else seen this behavior.
Utilities.formatDate seems to be working fine.
You have Apr 30 midnight in GMT-1 but then you tell it to format this date in a different timezone GMT, or more explicity GMT-0. The expected result is indeed Apr 29 23h.
The second parameter in Utilities.formatDate must be the timezone you desire.
这篇关于Utilities.formatDate日期未设置正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!