【发布时间】:2021-01-29 09:17:22
【问题描述】:
我一直在尝试使用 date-fns 格式化日期,但一直失败。基本上我在momentJS上工作得很好,但在date-fns上却不行:
这是我的约会日期:
"10-13-20" // month, day, and year
现在有了 momentJS,它就可以像这样工作了:
let result = moment("10-13-20", 'MM-DD-YY').format()
// result = "2020-10-13T00:00:00-06:00"
所以我尝试使用 date-fns 做同样的事情,但没有运气。谁能指出我正确的方向?提前致谢!
let result = format(new Date("10-13-20"), 'MM-DD-YY') // Not working
【问题讨论】:
-
new Date("10-13-20")至少在 Firefox 和 Safari 中返回无效的日期。见Why does Date.parse give incorrect results?
标签: javascript date momentjs date-fns