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?
Advertisement
Answer
You messed up the time:
HH:mm:ss
not HH:MM:ss
MM
is for month and mm
is for minute – docs