将UTC转换为当地时间 [英] Javascript to convert UTC to local time

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

问题描述

可以说JSON解析字符串UTC的日期如下:

  2012-11-29 17:00:34 UTC 

现在,如果要将本UTC日期转换为当地时间,我该怎么做? p>

感谢您的回答



=====



然后,如何将其格式化为其他像yyyy-MM-dd HH:mm:ss z?



这个日期.toString('yyyy-MM-dd HH:mm:ss z'); 永不解决:/

解决方案

尝试:

  var date = new Date('2012-11-29 17:00:34 UTC' ); 
date.toString();


Okay, say JSON parse string UTC date as below:

2012-11-29 17:00:34 UTC

Now if I want to convert this UTC date to my local time, how can I do this?

Thanks for the answer

=====

Then, how do I format it to something else like 'yyyy-MM-dd HH:mm:ss z'?

This date.toString('yyyy-MM-dd HH:mm:ss z'); never work out :/

解决方案

Try:

var date = new Date('2012-11-29 17:00:34 UTC');
date.toString();

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

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