Date-fns: Incorrect date with format ?

Created on 19 Jun 2018  路  3Comments  路  Source: date-fns/date-fns

I am trying to use the format method to display a date in a specific format. But resulting string has a month out of date. Here is my code:

const d = format(new Date('2018-02-19'), 'MM/DD/YYYY');

this gives me: 02/50/2018

I am doing something wrong there ?

Most helpful comment

Since 8th alpha, the correct token for day of month is dd (lowercase) and the correct token for year is yyyy (also lowercase). See: https://date-fns.org/v2.0.0-alpha.10/docs/format

All 3 comments

Since 8th alpha, the correct token for day of month is dd (lowercase) and the correct token for year is yyyy (also lowercase). See: https://date-fns.org/v2.0.0-alpha.10/docs/format

So, it should be actually 'MM/dd/yyyy'

My bad, thanks!

Was this page helpful?
0 / 5 - 0 ratings