moment.js-差异分钟返回不正确的值
我有两个带有DateTime的变量 - 一个包含cookie(UTC)的值,另一个包含UTC中的当前时间:
var expiration = moment(Date.parse($.cookie("ecookie")));
var current = moment().utc();
console.log(current.format('MMMM Do YYYY, h:mm:ss a'));
console.log(expiration.format('MMMM Do YYYY, h:mm:ss a'));
输出在变量中显示值:
5月20日,2022年,2:17:37:37 PM PM
5月20日,3:14:11 pm
为什么diff方法返回值63(分钟时的时间差)?:
current.diff(expiration, "minutes") // 63
应该在60分钟以下。我缺少什么作品?
编辑:
将cookie值存储在ISO 8601格式中解决问题
I have two variable populated with datetime - one containing value from cookie (utc), the otherone containing current time in utc:
var expiration = moment(Date.parse($.cookie("ecookie")));
var current = moment().utc();
console.log(current.format('MMMM Do YYYY, h:mm:ss a'));
console.log(expiration.format('MMMM Do YYYY, h:mm:ss a'));
output showing values in variables:
May 20th 2022, 2:17:37 pm
May 20th 2022, 3:14:11 pm
Why is the diff method returning value 63 (time difference in minutes) ?:
current.diff(expiration, "minutes") // 63
It should be under 60 minutes. What piece am I missing ?
EDIT:
Storing the cookie value in ISO 8601 format solves the issue
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论