将UTC日期时间转换为本地日期时间 [英] Convert UTC datetime to local datetime
问题描述
我多次尝试将utc datetime转换为本地日期时间,但我失败了。我的utc日期时间格式为
I tried many times to convert utc datetime to local datetime,and I have failed. My utc datetime format is
Fri Mar 8 23:12:27 UTC + 0200 2013
Fri Mar 8 23:12:27 UTC+0200 2013
此外,我的JavaScript代码是
Also my JavaScript code is
var time = Date(param_time);//param_time is /Date(1362866006646)/
然后时间 Sun Mar 10 00 :21:54 UTC + 0200 2013 我需要将日期时间设为 2008-01-28T20:24:17Z ,因为我会将本地日期时间转换为漂亮的日期时间。
And then time is being Sun Mar 10 00:21:54 UTC+0200 2013 I need to datetime as 2008-01-28T20:24:17Z because I will convert local datetime to pretty datetime.
http://ejohn.org/files/pretty.js
我该怎么做?我在stackoverflow上查看了很多问题,但是没有人能够正常工作。谢谢。
How can I do this ? I looked at many questions on stackoverflow but no one does it work. Thank you.
推荐答案
为了格式化你的日期
正确使用< a href =https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date/toISOString\"rel =noreferrer> toISOString()
:
In order to format your Date
correctly use toISOString()
:
var time = param_time.toISOString();
请注意 param_time
必须是有效的日期
对象。
Note that param_time
needs to be a valid Date
object.
- MDN:
日期
(部分:语法,示例:ISO 8601格式的日期)
- MDN:
Date
(sections: Syntax, Example: ISO 8601 formatted dates)
这篇关于将UTC日期时间转换为本地日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!