我将moment
对象定义为:
var moment = require('moment');
moment('2015-12-20T12:00:00+02:00');
当我打印它时,我得到:
_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
如何正确获取_tzm
? (假设它以分钟为单位的偏移量)
谢谢,
答案 0 :(得分:18)
只需像访问任何对象一样访问该属性
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>
另一种选择是解析日期并获得区域
moment.parseZone('2015-12-20T12:00:00+02:00').utcOffset(); // 120
// or
moment().utcOffset('2015-12-20T12:00:00+02:00')._offset; // 120