将UTC日期时间转换为本地日期时间 [英] Convert UTC date time to local date time
本文介绍了将UTC日期时间转换为本地日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从服务器我得到这种格式的日期时间变量: 6/29/2011 4:52:48 PM
并且它是UTC时间。我想使用JavaScript将其转换为当前用户的浏览器时间。
From the server I get a datetime variable in this format: 6/29/2011 4:52:48 PM
and it is in UTC time. I want to convert it to the current user’s browser time using JavaScript.
如何使用JavaScript或jQuery完成此操作?
How this can be done using JavaScript or jQuery?
推荐答案
在将字符串转换为javascript中的日期之前,将UTC附加到字符串中:
Append 'UTC' to the string before converting it to a date in javascript:
var date = new Date('6/29/2011 4:52:48 PM UTC');
date.toString() // "Wed Jun 29 2011 09:52:48 GMT-0700 (PDT)"
这篇关于将UTC日期时间转换为本地日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文