[英]Issue with Parsing Date and Time Using Date-FNS
I have here a date and time and I'm wondering its outputting an incorrect date and time.我在这里有一个日期和时间,我想知道它输出的日期和时间不正确。
2022-05-19T21:53:00+00:00
. 2022-05-19T21:53:00+00:00
。 Its currently outputting May 20. It should be May 19 still?它目前正在输出 5 月 20 日。应该还是 5 月 19 日?
CODESANDBOX: CLICK HERE代码沙盒: 点击这里
import { format, parseISO } from "date-fns";
let date = "2022-05-19T21:53:00+00:00";
document.getElementById("app").innerHTML = `
<div>${format(parseISO(date), "LLL dd, y hh:mm bbb")}</div>
`;
You don't actually need date-fns
you can simply use a native Date with toLocaleDateString()
.您实际上并不需要
date-fns
,您可以简单地将本机Date与toLocaleDateString()
一起使用。
let date = "2022-05-19T21:53:00+00:00"; const options = { month: 'long', day: 'numeric', year: 'numeric', hour: 'numeric', minute: 'numeric', timeZone: 'UTC' }; const dateLocaleString = new Date(date).toLocaleDateString('en', options); document.getElementById("app").innerHTML = ` <div>${dateLocaleString}</div> `;
<div id="app"></div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.