Moment.js转换为日期对象 [英] Moment.js transform to date object
本文介绍了Moment.js转换为日期对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用Moment.js我无法将正确的时刻对象转换为带时区的日期对象。我无法获得正确的日期。
Using Moment.js I can't transform a correct moment object to a date object with timezones. I can't get the correct date.
示例:
var oldDate = new Date(),
momentObj = moment(oldDate).tz("MST7MDT"),
newDate = momentObj.toDate();
console.log("start date " + oldDate)
console.log("Format from moment with offset " + momentObj.format())
console.log("Format from moment without offset " + momentObj.utc().format())
console.log("(Date object) Time with offset " + newDate)
console.log("(Date object) Time without offset "+ moment.utc(newDate).toDate())
推荐答案
使用此选项将时刻对象转换为日期对象:
Use this to transform a moment object into a date object:
来自 http://momentjs.com/docs/#/displaying/as-javascript-date/
moment().toDate();
收益率:
Tue Nov 04 2014 14:04:01 GMT-0600 (CST)
这篇关于Moment.js转换为日期对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文