将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)"