Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
356 views
in Technique[技术] by (71.8m points)

javascript - Moment.js转换为日期对象(Moment.js transform to date object)

Using Moment.js I can't transform a correct moment object to a date object with timezones.(使用Moment.js,我无法将正确的矩对象转换为具有时区的日期对象。)

I can't get the correct date.(我找不到正确的日期。) Example:(例:) 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())   ask by vadim.zhiltsov translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use this to transform a moment object into a date object:(使用它可以将矩对象转换为日期对象:)

From http://momentjs.com/docs/#/displaying/as-javascript-date/(从http://momentjs.com/docs/#/displaying/as-javascript-date/) moment().toDate(); Yields:(产量:) Tue Nov 04 2014 14:04:01 GMT-0600 (CST)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...