简体   繁体   中英

How to get Timezone offset from moment Object?

I have moment Object defined as:

var moment = require('moment');

moment('2015-12-20T12:00:00+02:00');

When I print it, I get:

_d: Sun Dec 20 2015 12:00:00 GMT+0200 (EET)
_f: "YYYY-MM-DDTHH:mm:ssZ"
_i: "2015-12-20T12:00:00+02:00"
_isAMomentObject: true
_isUTC: false
_locale: r
_pf: Object
_tzm: 120

How to fetch by right way _tzm ? (suppose its offset in minutes)

Thanks,

Just access the property like you would in any object

 var result = moment('2015-12-20T12:00:00+02:00'); document.body.innerHTML = result._tzm; 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.1/moment.min.js"></script> 

Another option would be to parse the date and get the zone

moment.parseZone('2015-12-20T12:00:00+02:00').utcOffset(); // 120
// or
moment().utcOffset('2015-12-20T12:00:00+02:00')._offset; // 120

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM