convert time of certain timezone to UTC using momemtjs

≡放荡痞女 提交于 2020-01-06 18:33:48

问题


I have a time in a specific timezone , I want to covert it to UTC . how can I achieve that using moment timezone ?

http://momentjs.com/timezone/

in the documentation this is how to convert : jun.tz('America/Los_Angeles').format('ha z');

I am just not sure what timezone name to pass to convert it to UTC, or is there another function to use?


回答1:


You can easily construct a moment in a specific time zone by using the moment.tz(...) syntax. This is slightly different from doing conversions with the .tz(...) function of an existing moment object, which is what you showed in your question.

var m = moment.tz('2016-03-25 08:00:00', 'America/Los_Angeles')

Once you have a moment object, you can convert it to UTC by calling the .utc() function. You can then format it however you like.

moment.tz('2016-03-25 12:34:56', 'America/Los_Angeles').utc().format()
// output: "2016-03-25T19:34:56+00:00"


来源:https://stackoverflow.com/questions/36214634/convert-time-of-certain-timezone-to-utc-using-momemtjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!