將 Date 物件轉換為 moment 物件
要將 Javascript Date 物件轉換為片刻(片刻物件),只需呼叫 moment
並將 Date 作為引數傳遞
moment(new Date());
// Moment {_isAMomentObject: true, _i: Sun Jul 31 2016 11:08:02 GMT+0300 (Jerusalem Daylight Time), _isUTC: false, _pf: Object, _locale: Locale…}
要將時刻轉回 Javascript 日期,請使用 .toDate()
方法
var now = new Date();
var mom = moment(now)
//undefined
mom
// Moment {_isAMomentObject: true, _i: Sun Jul 31 2016 11:10:32 GMT+0300 (Jerusalem Daylight Time), _isUTC: false, _pf: Object, _locale: Locale…}
mom.toDate()
// Sun Jul 31 2016 11:10:32 GMT+0300 (Jerusalem Daylight Time)