The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Parse An ISO Date In JavaScript

TODO: Pull subtitle into page object

The native `Date` JavaScript object can parse ISO style date string. For example, this one without a timezone:

code_start_default_section code_end_default_section

And all the other ones listed here

Note, this is done without using `Data.parse()` which is "strongly discouraged due to browser differences and inconsistencies." (source

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

Parse An ISO Date In JavaScript

-- p

The native `Date` JavaScript object can parse ISO style date string. For example, this one without a timezone:

-- code/
-- javascript

const dateString = '2021-11-12T02:03:03'
const dateObject = new Date(dateString)

-- /code

-- p

That code will produce a date object that will print out this if logged:

-- code/

2021-11-12T07:03:03.000Z

-- /code

-- p

Note that the time has moved to Zulu (or GMT) time. That is, the hour shifted from 2 to 7.

-- p

Once the date is parsed, you use functions like:

-- code/
-- javascript

.getFullYear()
.getMonth()
.getDate()

-- /code

-- p

And all the other ones <<link|listed here|https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date>>

-- p

Note, this is done without using `Data.parse()` which is "strongly discouraged due to browser differences and inconsistencies." (<<link|source|https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse)>>


-- categories
-- JavaScript

-- metadata
-- date: 2021-11-13 21:20:30
-- id: 20tgnu6w
-- status: draft
-- type: post
-- SCRUBBED_NEO: false
-- site: aws