I have a collection of date strings stored in a database in this format:
2018-06-28T14:06:26.524Z
2018-07-02T10:32:18.818Z
2018-07-06T15:08:50.233Z
I need to convert these dates into a format like this on the frontend:
28 June 2018 14:06:26
02 July 2018 10:32:18
06 July 2018 08:50:23
My attempt at doing this using date-fns is:
format(new Date(date), 'dd MMMM yyyy HH:MM:ss')
The problem is that the dates returned from the above are incorrect:
2018-06-28T14:06:26.524Z
returns 28 June 2018 15:06:26
2018-07-02T10:32:18.818Z
returns 02 July 2018 11:07:18
2018-07-06T15:08:50.233Z
returns 06 July 2018 16:07:50
What am I doing wrong here and how to I fix this so the dates are returned correctly?
You messed up the time:
HH:mm:ss
not HH:MM:ss
MM
is for month and mm
is for minute - docs
You misspelled HH:MM:ss
should be HH:mm:ss
look at this list for an explanation on all formats: Date formats
Example:
dd MMMM yyyy HH:mm:ss: 22 August 2006 06:30:07
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