Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
317 views
in Technique[技术] by (71.8m points)

javascript - 将UTC日期时间转换为本地日期时间(Convert UTC date time to local date time)

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

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

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...