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.
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)
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).
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.
The Date object handles 8601 as it's first parameter:
var d = new Date("2014-04-07T13:58:10.104Z"); console.log(d.toString());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With