简体   繁体   English

使用MomentJS格式化日期,无需本地时间调整

[英]Format a date with MomentJS, without local time adjustment

I want to display a unix timestamp (which is in UTC) as a formatted date. 我想将unix时间戳(以UTC格式)显示为格式化日期。

I also want to keep it in the UTC timezone (so no change to the hours based on TZ). 我也想将其保留在UTC时区(因此,基于TZ的小时数保持不变)。 How can I do this? 我怎样才能做到这一点?

Example: 例:

moment(unix_timestamp).format('MMMM D, YYYY - H:mm:SS.SSSS') converts the output into the computer's local time. moment(unix_timestamp).format('MMMM D, YYYY - H:mm:SS.SSSS')将输出转换为计算机的本地时间。

Moment Docs: 时刻文档:

Found this section in the docs, but none of the options seem to work: https://momentjs.com/guides/#/parsing/local-utc-zone/ 在文档中找到了本节,但所有选项似乎都不起作用: https : //momentjs.com/guides/#/parsing/local-utc-zone/

As far as documentation states: 据文档指出:

Note that if you use moment() or moment.utc() to parse a date with a specified offset, the date will be converted from that offset to either local or UTC: 请注意,如果您使用moment()或moment.utc()解析具有指定偏移量的日期,则该日期将从该偏移量转换为本地或UTC:

moment('2016-01-01T00:00:00+02:00').format() //converted to local

moment.utc('2016-01-01T00:00:00+02:00').format() //treated as UTC

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

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