How to get Timezone offset from moment Object?

43,473

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
Share:
43,473
snaggs
Author by

snaggs

Mostly work on demos and little Web/Mobile projects. Ask a lot of questions :)

Updated on January 18, 2020

Comments

  • snaggs
    snaggs over 4 years

    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,