使用momemtjs将特定时区的时间转换为UTC [英] convert time of certain timezone to UTC using momemtjs

查看:220
本文介绍了使用momemtjs将特定时区的时间转换为UTC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在特定时区有时间,我想将它隐瞒UTC.如何使用时区时区实现这一目标?

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/

在文档中,这是如何进行转换的方法: jun.tz('America/Los_Angeles').format('ha z');

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

我只是不确定要传递哪个时区名称以将其转换为UTC,还是有其他功能要使用?

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

推荐答案

您可以使用moment.tz(...)语法轻松地在特定时区构造一个时刻.这与使用现有时刻对象的.tz(...)函数进行转换略有不同,这就是您在问题中所显示的.

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')

一旦有了moment对象,就可以通过调用.utc()函数将其转换为UTC.然后,您可以根据自己的喜好对其进行格式化.

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"

这篇关于使用momemtjs将特定时区的时间转换为UTC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆