Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert yyyy-MM-ddTHH:mm:ss.fffZ to DateTime in JavaScript manually

I receive from a Webservice a String with a date in this format:

yyyy-MM-ddTHH:mm:ss.fffZ

I need to convert that String with JavaScript to a normal DateTime but without using the new Date('yyyy-MM-ddTHH:mm:ss.fffZ') because I'm using an old version of JavaScript that not support that conversion. I can split that string and get the:

  • Year
  • Month
  • Days
  • Time

but how to manipulate the time zone "fffZ" Any suggestions?

like image 659
Martín Avatar asked Jan 09 '13 15:01

Martín


1 Answers

Here's a one liner from John Resig:

var date = new Date((time || "").replace(/-/g,"/").replace(/[TZ]/g," ")),
like image 68
Jan Jongboom Avatar answered Sep 30 '22 15:09

Jan Jongboom