How to get Timezone offset from moment Object?

前端 未结 1 1805
野趣味
野趣味 2021-01-07 20:09

I have moment Object defined as:

var moment = require(\'moment\');

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

When I print it, I

相关标签:
1条回答
  • 2021-01-07 20:22

    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
    
    0 讨论(0)
提交回复
热议问题