Dale Nguyen
Dale Nguyen

Reputation: 1980

dayjs returns wrong date with format

I'm trying to convert a date to a readable format.

For example:

var dayjs = require('dayjs')

const date = '1989-08-12T01:00:00.000Z'
console.log(dayjs(date).format('DD/MM/YYYY'))

The result shows: 11/08/1989

Expected behavior A clear and concise description of what you expected to happen.

I expect that the log should return 12/08/1989 instead of 11/08/1989

Day.js Version: v1.8.16

Not sure if I miss any parameters or not. Thanks,

Upvotes: 4

Views: 12631

Answers (1)

hong4rc
hong4rc

Reputation: 4103

Your input is timezone 0, but the output is your timezone. You can change your code to

var dayjs = require('dayjs')

const date = '1989-08-12T01:00:00.00' // remove 0Z
console.log(dayjs(date).format('DD/MM/YYYY'))

Your problem is the same with https://github.com/iamkun/dayjs/issues/323

Upvotes: 5

Related Questions