javascript - 时刻时区,设置默认时区

标签 javascript timezone momentjs

我想在我的网络应用程序中在同一时区工作,我尝试使用时区默认功能 moment.tz.setDefault("欧洲/马德里"); 日期转换(json 格式)不好,默认减去一天

这是我的小东西

http://plnkr.co/edit/xsugHtDLLUfxugCJRwIZ?p=preview

谢谢

 var jsonDate = "/Date(118101600000)/"; // DD/MM/YY = 29/09/1973 

 alert(moment(jsonDate).format("DD/MM/YY")); // conversion ok

 moment.tz.setDefault("Europe/Madrid");

 alert(moment(jsonDate).tz('Europe/Madrid').format("DD/MM/YY")); // substract one day by default 28/09/1973
 alert(moment(jsonDate).format("DD/MM/YY"));                     // substract one day by default 28/09/1973

最佳答案

@kaken

你能检查一下吗link

我点击该链接来解决时区问题。

例如:moment(jsonDate).zone("+03:00");//时刻可以解析JsonDate

要使用命名时区,请包含 Moment Timezone 并使用 .tz()

// determines the correct offset for America/Phoenix at the given moment

moment(1369266934311).tz('America/Phoenix').format('YYYY-MM-DD HH:mm')

// always "2013-05-22 16:55"

关于javascript - 时刻时区,设置默认时区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29819652/

相关文章:

HTML5 日期时间-本地 (Chrome) : How to input datetime in current time zone

javascript - 如何在 Bluemix 上安装 moment-timezone.js?

javascript - 我无法查看数据类型的所有元素

javascript - 将 Memoizee 与 node.js 结合使用

javascript - 除非先单击同级元素,否则无法复制可拖动元素

不同语言环境和时区的 Javascript 日期对象

datetime - 在不更改 Windows 系统时钟的情况下伪造时间

javascript - CET 时区中的日期到用户时区的日期

javascript - HTML 日期字段无法设置回来自后端的日期字段

javascript - ES6 : constructor can't declare as arrow function?