Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

From the server I get a datetime variable in this format: 6/29/2011 4:52:48 PM and it is in UTC time.

(从服务器上,我得到一个datetime变量,格式为: 6/29/2011 4:52:48 PM ,它是UTC时间。)

I want to convert it to the current user's browser time using JavaScript.

(我想使用JavaScript将其转换为当前用户的浏览器时间。)

How this can be done using JavaScript or jQuery?

(如何使用JavaScript或jQuery完成此操作?)

  ask by Amr Elgarhy translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
445 views
Welcome To Ask or Share your Answers For Others

1 Answer

Append 'UTC' to the string before converting it to a date in javascript:

(将'UTC'附加到字符串之前,将其转换为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)"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...