如何从时刻对象获得时区偏移? [英] How to get Timezone offset from moment Object?
本文介绍了如何从时刻对象获得时区偏移?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有时刻
对象定义为:
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
如何正确获取 _tzm
? (假设其以分钟为单位的偏移量)
How to fetch by right way _tzm
? (suppose its offset in minutes)
谢谢,
推荐答案
像在任何对象中一样访问该属性
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
这篇关于如何从时刻对象获得时区偏移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文