Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing ISO 8601 date in Javascript

Need help/tips on converting an ISO 8601 date with the following structure into javascript.

CCYY-MM-DDThh:mm:ssTZD 

I'd like to format the date like so:

January 28, 2011 - 7:30PM EST 

I'd like to keep this solution as clean and minimal as possible.

like image 864
Slythic Avatar asked Jan 28 '11 14:01

Slythic


People also ask

What is ISO 8601 date format JavaScript?

The ISO 8601 date format is as follows: YYYY-MM-DDTHH:mm:ss. sssZ. The characters represent the following data: YYYY – the current year, in four digits (e.g. 2020)

How do I read the ISO 8601 date format?

ISO 8601 represents date and time by starting with the year, followed by the month, the day, the hour, the minutes, seconds and milliseconds. For example, 2020-07-10 15:00:00.000, represents the 10th of July 2020 at 3 p.m. (in local time as there is no time zone offset specified—more on that below).

How do I convert ISO to date?

Use the Date() constructor to convert an ISO string to a date object, e.g. new Date('2023-07-21T09:35:31.820Z') . The Date() constructor will easily parse the ISO 8601 string and will return a Date object.


1 Answers

The Date object handles 8601 as it's first parameter:

var d = new Date("2014-04-07T13:58:10.104Z");  console.log(d.toString());
like image 170
Rob Evans Avatar answered Sep 19 '22 04:09

Rob Evans