DEV Community

Ryan Westlund
Ryan Westlund

Posted on

JS date parsing aaaaargghhh

Aaaarghhh I just had to deal with this in depth. I used to think Javascript's "wildcard" date parsing was handy enough to kinda make up for not having strptime. No. It absolutely doesn't.

I ran into some weird situation where it could parse the date if I used / as a separator, but not -, because it doesn't actually have the flexibility of strptime. It's also apparently not consistent across browsers...

And goddamn, how do I parse something as UTC. Date.UTC doesn't take a string. The +00:00 suffix that Python outputs isn't recognized, but Z is. Date.parse is the backend for new Date and doesn't seem to have any way to parse as UTC. Ugh.

Discussion (0)