正确的方法来转换javascriptdate时区

我正在使用以下格式返回时间值的API:

2013:02:27T06:39:25 

请注意缺less时区的标识符。

从API文档:

https://partner-api.groupon.com/ledger

 "Transaction timestamp of the ledger entry in the affiliate's time-zone.. The format is YYYY-MM-DDThh:mm:ss.. Example 2013:02:27T06:39:25" 

API响应时区显然是EST(子公司的时区)。 从这个派生UTC时区值的最好方法是存储在MongoDB数据库中。

格式为YYYY-MM-DDThh:mm:ss ..示例2013:02:27T06:39:25“

看起来在这个文档示例中有一个错误,因为它与build议的格式不匹配( 2013:02:27T06:39:25应该是2013-02-27T06:39:25 )。

该页面稍后的示例响应与预期的格式匹配:

 "orderDate": "2012-11-21T04:57:03" 

我会build议使用moment-timezone – 它有一个moment.tz()构造函数将parsingdatestring,并设置预期的时区:

 > var moment = require('moment-timezone'); > var orderDate = moment.tz("2012-11-21T04:57:03", "America/New_York") > orderDate.toString() 'Wed Nov 21 2012 04:57:03 GMT-0500' > orderDate.toISOString() '2012-11-20T17:57:03.000Z'