更改 JavaScript 日期对象中的时区缩写


Changing Time Zone Abbreviation in javascript date object

如何在javascript日期对象中格式化时区缩写

在 JavaScript 中获取new Date()对象时,它产生输出为

Thu Oct 30 2014 00:00:00 GMT+0530 (India Standard Time)在窗口中

Thu Oct 30 2014 00:00:00 GMT+0530 (IST)在Linux中...

我需要的是 (IST) 中的输出,所以我可以使用 strtotime()

您实际上不需要此转换。只需使用(India Standard Time)后缀,或者根本没有后缀,就可以正常工作。例如:

echo(strtotime("Thu Oct 30 2014 00:00:00 GMT+0530 (IST)") . " / " .
     strtotime("Thu Oct 30 2014 00:00:00 GMT+0530") . " / " .
     strtotime("Thu Oct 30 2014 00:00:00 GMT+0530 (India Standard Time)"));

返回

1414627200 / 1414627200 / 1414627200

演示

所以我对你的问题的回答是,我认为不可能获得官方时区缩写,但我对你的问题的解决方案是简单地使用你已经拥有的格式(或者如果后缀在另一种语言中引起问题,只需省略后缀)。

或者,您可以先将时区转换为 UTC,然后将其提供给 PHP:

//some other way to generate this Date object is of course fine too
var d = new Date(/*your date object*/);
//converts it from ms -> sec, to the format PHP uses
var unix = Math.floor(d.getTime() / 1000);