【问题标题】:Changing Time Zone Abbreviation in javascript date object在 javascript 日期对象中更改时区缩写
【发布时间】:2014-11-18 12:27:00
【问题描述】:

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

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

Thu Oct 30 2014 00:00:00 GMT+0530 (India Standard Time)windows

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

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

【问题讨论】:

标签: javascript php date timezone strtotime


【解决方案1】:

您实际上不需要这种转换。只需使用(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

Demo.

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

或者,您可以先将时区转换为 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);

【讨论】:

  • 好吧好吧...但是在我的服务器中,第三个输出没有得到
  • 那我建议使用不带后缀的字符串。 GMT+0530 部分应该已经处理了时区。
  • 我没有传递数据对象,它来自 jQuery calander
猜你喜欢
  • 1970-01-01
  • 2020-04-02
  • 2020-10-09
  • 1970-01-01
  • 2015-01-29
  • 2019-11-18
  • 1970-01-01
  • 2015-12-22
  • 2018-09-11
相关资源
最近更新 更多