简体   繁体   English

如何将 UTC 日期/时间转换为 MDT 和军用时间以进行反应应用?

[英]how to convert UTC date/time into MDT and military time for react application?

I am trying to convert UTC into MDT (mountain time) format.我正在尝试将 UTC 转换为 MDT(山地时间)格式。 I am not sure which moment format require to convert date time into MDT.我不确定将日期时间转换为 MDT 需要哪种时刻格式。 i tried moment.fromOADate(41493) but not working.我试过 moment.fromOADate(41493) 但没有工作。 TIA!蒂亚!

Mountain time is GMT -6, so you should be able to use moment().utcOffset(-6)山区时间是格林威治标准时间 -6,所以你应该能够使用 moment().utcOffset(-6)

https://en.wikipedia.org/wiki/Mountain_Time_Zone https://en.wikipedia.org/wiki/Mountain_Time_Zone

https://momentjscom.readthedocs.io/en/latest/moment/03-manipulating/09-utc-offset/ https://momentjscom.readthedocs.io/en/latest/moment/03-manipulating/09-utc-offset/

If you're worried about accounting for daylight savings time and can't just subtract 6 hours, you might also look into the moment.js timezone library .如果您担心考虑夏令时并且不能只减去 6 小时,您还可以查看moment.js 时区库

You could say something like is described here and do var zone = moment.tz.zone('America/Chihuahua') (this is mountain time), then get your time offset with zone.parse(utcTimestamp)您可以说类似这里描述的内容并执行var zone = moment.tz.zone('America/Chihuahua') (这是山区时间),然后使用zone.parse(utcTimestamp)获取时间偏移

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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