Convert UTC Date to datetime string Javascript
17,368
Solution 1
str=str.replace(/T|\:\d\dZ/g,' ')
Solution 2
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.
Related videos on Youtube
Author by
Sinal
Software developer in Ruby on Rails & ReactJS + TypeScript + React Native Now Python, AI/ML & Computer Vision You can contact me via LinkedIn.
Updated on June 24, 2022Comments
-
Sinal almost 2 years
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.
Thanks
-
Mr.Hunt over 11 yearsIn IE8 it returns NaN. >>new Date("2011-10-30T18:30:00Z").toString() "NaN"
-
NT3RP over 11 yearsInteresting. Does
new Date(Date.parse("2011-10-30T18:30:00Z")).toString()
work in IE8? -
Mr.Hunt over 11 yearsno, it returns "NaN" as well. Infact, it fails while doing Date.parse