我需要获取UTC格式的当前日期和时间,而不考虑当前时区。因此,如果我当前的本地时间是12:00,并且我在UTC+1:00,我希望获得12:00UTC。
如何在moment.js或day.js中轻松实现这一点?
发布于 2019-11-21 02:45:58
为此,您不需要库。
new Date() // gets a Date object representing "now" (internally in UTC)
new Date().toISOString() // returns "now", in UTC, formatted as an ISO 8601 string如果你真的想使用Moment:
moment.utc() // gets a Moment object representing "now", set to UTC mode
moment.utc().format() // returns "now", in UTC, with the default ISO 8601 format
moment.utc().toISOString() // does the same thing
moment().toISOString() // does the same thingDay.js需要UTC plugin,但其工作方式类似于Moment。
https://stackoverflow.com/questions/58955103
复制相似问题