What is wrong?
getUTCDay
returns the day of the week, not the day of the month:
The
getUTCDay()
method returns the day of the week in the specified date according to universal time, where 0 represents Sunday.
getUTCMonth
returns the month, 0 based:
The value returned by
getUTCMonth
is an integer between 0 and 11 corresponding to the month. 0 for January, 1 for February, 2 for March, and so on.
You want to use .getUTCDate
instead and add +1
to the return value of .getUTCMonth
:
var res = [a.getUTCDate(), a.getUTCMonth() + 1, a.getUTCFullYear()].join('-');