[英]Is this a bug in date-fns library, converting a date to UTC format give me wrong time
So I use date-fns to converting current date to UTC. 因此,我使用date-fns将当前日期转换为UTC。 This is my code : 这是我的代码:
import { format } from 'date-fns';
function currentDate() {
return format(Date.now(), 'YYYY-MM-DDTHH:MM:SSZ');
}
the output of this function is a date with this format : 2018-11-27T16:11:73+01:00
此函数的输出是具有以下格式的日期: 2018-11-27T16:11:73+01:00
As you can see in Time section, the seconds is 73 ( More then 60 ) 16:11:73
and this make a problem for my serverside code where I need to validate the user data, so obviously will fail when it want cast to date with this error : Cast to date failed for value "2018-11-27T16:11:73+01:00" at path currentDate
正如您在“时间”部分中看到的,秒数是73( 16:11:73
60) 16:11:73
,这对我需要验证用户数据的服务器端代码造成了问题,因此当它想要转换为日期时显然会失败发生此错误: Cast to date failed for value "2018-11-27T16:11:73+01:00" at path currentDate
Any idea guys? 有想法吗?
The format you are providing is wrong. 您提供的格式错误。
mm
, 分钟= mm
ss
(lowercased) 秒= ss
(小写) See full list here: https://date-fns.org/v1.9.0/docs/format 在此处查看完整列表: https : //date-fns.org/v1.9.0/docs/format
SS
is 1/100 of second SS
是1/100秒
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.