我只是想獲取一個輸入字符串並將其轉換爲日期對象。爲什麼moment.js返回這個日期錯誤?
moment.utc('2000-01-01T00:00:00.000Z').toDate()
但它返回......
Fri Dec 31 1999 19:00:00 GMT-0500 (EST)
感謝
我只是想獲取一個輸入字符串並將其轉換爲日期對象。爲什麼moment.js返回這個日期錯誤?
moment.utc('2000-01-01T00:00:00.000Z').toDate()
但它返回......
Fri Dec 31 1999 19:00:00 GMT-0500 (EST)
感謝
這是一個有效的JavaScript日期對象。您可以在Chrome或Firefox打開控制檯,然後輸入以下測試:
// Mon Nov 24 2014 09:54:00 GMT-0800 (PST) (looks the same as your example)
console.log(new Date());
如果要格式化出來moment.js的值,你可以使用它的格式方法和口罩。
// Example: November 24th 2014, 09:58:12am
var fdate = moment().format('MMMM Do YYYY, h:mm:ss a');
Moment.js不會修改原型,它只是簡單地包裝它。
如果你想將字符串轉換爲使用moment.js約會對象,你可以把它作爲這樣的:
moment(your_date); // Unless in UTC mode this will display as local time
在你的情況下,你正在使用的UTC mode。
他需要一個日期對象... – 2014-11-24 18:13:23
感謝@Bojangles的更正。 – 2014-11-25 17:24:45
2000-01-01T00:00:00.000Z
是GMT日期/時間。
使用moment.utc("2000-01-01T00:00:00.000Z").toDate()
根據您的timzone設置返回此日期/時間。
參見:http://www.digitoffee.com/programming/get-local-time-utc-using-moment-js/94/
希望它能幫助。
我在編輯評論的同時寫下了答案......只是想幫忙。 – edouard 2014-11-24 18:03:44
只是一個說明:*是*正確的日期/時間。 '00:00:00 UTC'(又名'00:00:00.000Z')*是*'19:00:00 EST' – apsillers 2014-11-24 17:51:56