javascript - 解析cookie过期日期

标签 javascript cookies momentjs

过期日期在 Chome 开发工具中看起来不错: enter image description here

然后当我记录它时,它看起来像这样:
enter image description here

我的问题是如何用 moment.js 之类的东西解析它?

我用 moment 尝试了各种东西,但总是 1970 年

console.log(moment(1561561645.546124));
// result moment("1970-01-19T03:46:01.645")

最佳答案

您应该使用 13 位数字乘以 1000 的纪元时间

可以引用momentjs文档,它只支持毫秒(13位)的Epoch

与 new Date(Number) 类似,您可以通过传递表示自 Unix 纪元以来的毫秒数的整数值来创建时刻

https://momentjs.com/docs/#/parsing/unix-timestamp-milliseconds/

console.log(moment(1561561645.546124 * 1000));

console.log(moment(1561561645.546124 * 1000));
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.js" integrity="sha256-H9jAz//QLkDOy/nzE9G4aYijQtkLt9FvGmdUTwBk6gs=" crossorigin="anonymous"></script>

关于javascript - 解析cookie过期日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56775127/

相关文章:

javascript - 当年份设置为20年时防止Moment js猜年份

javascript - 如何从 node.js 检索数据到 Ajax?

javascript - Google Sheets API Node 客户端库最小示例

momentjs - 时刻与 date-fns 语言环境日期格式

Javascript window.location 被一次又一次调用 IE-8

禁用cookie的php setcookie行为

javascript - "moment is not defined"使用 moment.js

javascript - 保存 InDesign 文档后仅运行一次事件监听器吗?

javascript - 什么(浏览器插件?)将 p 定义为字符串 www311

ruby-on-rails - 在 Rails cookie 中存储/检索值