Search code examples
javascriptjquerydatetimestampiso

Convert iso timestamp to date format with Javascript?


This seems like a pretty simple question but I can't seem to get an answer for it. How can I convert an iso timestamp to display the date/time using JavaScript?

Example timestamp: 2012-04-15T18:06:08-07:00

Any help is appreciated, Google is failing me. Thank you.


Solution

  • Pass it to the Date constructor.

    > var date = new Date('2012-04-15T18:06:08-07:00')
    > date
      Mon Apr 16 2012 04:06:08 GMT+0300 (EEST)
    

    For more information about Date, check https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date.