Skip to content

Instantly share code, notes, and snippets.

@davissorenson
Last active February 21, 2021 15:46
Show Gist options
  • Save davissorenson/289f235ddcbd47a4bec1c61c3f0d36e9 to your computer and use it in GitHub Desktop.
Save davissorenson/289f235ddcbd47a4bec1c61c3f0d36e9 to your computer and use it in GitHub Desktop.
Parse RFC 3339 date with date-fns library using Unicode tokens (Unicode Technical Standard #35)

I don't guarantee this to be correct, but it should be a good starting point. Make sure you check the dates you're using first, especially details like whether or not you're using T in between date and time, and whether your format specifies fractions of a second.

import { parse } from "date-fns";

parse("2019-10-12T07:20:50Z", "yyyy-MM-dd'T'HH:mm:ssX", new Date());
// => Date Sat Oct 12 2019 10:20:50 GMT+0300 (Eastern European Summer Time)
@strarsis
Copy link

There is now a built-in method in date-fns, they also added the formats as constants:
https://date-fns.org/v2.17.0/docs/formatRFC3339

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment