2015-11-07 66 views
1

我正在使用日历插件,其中我希望Date对象与特定时区一起存储。我正在使用插件moment.jsmoment-timezone.js。 (new date(moment.tz(“2012-11-04 01:00:00-04:00”,“America/New_York”).format()));修改时区新日期javascript

获取:Date {Sun Nov 04 2012 05:00:00 GMT+0000}

我需要:Date {Sun Nov 04 2012 05:00:00 GMT-0400}

我使用PhoneGap的图书馆,我需要两个对象的日期。

window.plugins.calendar.createEvent(title, event_location, notes, start_date, end_date, function(message) { }, function(message) { }); 

插件保存事件在设备的日历,并检测是否该被发送的时区是从设备时区不同,并改变事件的时区。在设备的时区和事件中显示事件的事件时间。

回答

0

你问的是不可能的。 Date对象不能呈现除代码正在运行的本地时区以外的任何时区。此外,如果您已经拥有正确的本地日期,时间和偏移量,那么使用时区和时区几乎没有什么好处。只需使用parseZone保留偏移给定:

console.log(moment.parseZone("2012-11-04 01:00:00-04:00").format()); 
// "2012-11-04T01:00:00-04:00" 
+0

另外,如果你能告诉我,为什么* *你想要一个'Date'对象,我可以尝试提供一种替代。 –