moment.js-差异分钟返回不正确的值

发布于 2025-01-30 16:36:12 字数 613 浏览 2 评论 0原文

我有两个带有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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文