javascript 将UTC日期转换为日期时间字符串Javascript
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7708223/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert UTC Date to datetime string Javascript
提问by Sinal
I have a UTC date string, "2011-10-30T18:30:00Z", and I want to convert it to "2011-10-30 18:30". Can anyone give me some advice how to do this? I would appreciate for your time and consideration.
我有一个 UTC 日期字符串“2011-10-30T18:30:00Z”,我想将其转换为“2011-10-30 18:30”。谁能给我一些建议如何做到这一点?感谢您的时间和考虑。
Thanks
谢谢
采纳答案by kennebec
str=str.replace(/T|\:\d\dZ/g,' ')
回答by NT3RP
The easiest solution is to try the following:
最简单的解决方案是尝试以下操作:
var date = new Date("2011-10-30T18:30:00Z");
This will convert it into a normal Javascript date, at which point you can use whatever data operators you like.
这会将其转换为正常的 Javascript 日期,此时您可以使用任何您喜欢的数据运算符。