-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Description
Using datefns v 2.16.1
Given a date string
2020-12-27T08:00:00.000Z
The result of formatting the date with the specified format
yyyy-MM-dd : 2020-12-27
Y-MM-dd : 2021-12-27
Y is one year ahead.
Note that if the date string is
2020-12-26T08:00:00.000Z
where the day is "26" instead of "27" the value of Y is 2020 as expected
Some sample code below to replicate:
const {
format
} = require('date-fns');
let dString = '2020-12-27T08:00:00.000Z';
console.log('date string :', dString);
let dateToPublish;
dateToPublish = format(new Date(dString), 'yyyy-MM-dd');
console.log('format: yyyy-MM-dd :', dateToPublish);
dateToPublish = format(new Date(dString), 'Y-MM-dd');
console.log('format: Y-MM-dd :', dateToPublish);
The output :
date string : 2020-12-27T08:00:00.000Z
format: yyyy-MM-dd : 2020-12-27
format: Y-MM-dd : 2021-12-27
miaopeng, rowanc1, nickpedersen and f1yn
Metadata
Metadata
Assignees
Labels
No labels