admin管理员组文章数量:1394052
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,
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,
Share Improve this question asked Oct 21, 2019 at 17:16 Dale NguyenDale Nguyen 1,9804 gold badges24 silver badges37 bronze badges 6-
Try
date = '1989-08-12'
. What will be the result? – Daniyal Lukmanov Commented Oct 21, 2019 at 17:23 -
Your problem is your timezone
.format
format with your timezone. use.format('DD/MM/YYYY h:m:s')
and see log, you will understand – hong4rc Commented Oct 21, 2019 at 17:25 -
1
I think the problem is
utc
time difference. – Daniyal Lukmanov Commented Oct 21, 2019 at 17:25 - @DaniyalLukmanov it returns 12/08/1989. I guess, it is one way to solve it. About UTC time, can you elaborate that? I'm reading about too. – Dale Nguyen Commented Oct 21, 2019 at 17:27
- @Hongarc it shows 11/08/1989 9:0:0. Time is different...? – Dale Nguyen Commented Oct 21, 2019 at 17:28
1 Answer
Reset to default 5Your 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./iamkun/dayjs/issues/323
本文标签: javascriptdayjs returns wrong date with formatStack Overflow
版权声明:本文标题:javascript - dayjs returns wrong date with format - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744086357a2588596.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论