Skip to content

Help with formatISO #2366

Answered by devuxer
laurensiusadi asked this question in Q&A
Mar 24, 2021 · 1 comments · 3 replies
Discussion options

You must be logged in to vote
  1. Easiest way I know of is to just use the built-in JS functiontoISOString(), though it's not exactly the same as the date-fns docs.
const result = new Date(2019, 8, 18, 19, 0, 52).toISOString();
// "2019-09-18T19:00:52.000Z"
  1. You could kind of fudge it like this:
const result = format(new Date(2019, 8, 18, 19, 0, 52), "yyyy-MM-dd'T'HH:mm:ss'z'")
// "2019-09-18T19:00:52z"
  1. Finally, you could go into your OS settings and change the time zone to "(UTC) Coordinate Universal Time" (or equivalent), then try your code again. You should get exactly what's in the date-fns docs. (This is probably not practical unless you can count on your code always running on a server with this setting.)

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@safareli
Comment options

@laurensiusadi
Comment options

@Shyam-Chen
Comment options

Answer selected by laurensiusadi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants