- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在下个月的随机日期创建随机时间,这样
var time = new Date(now.getFullYear(),
now.getMonth() + 1,
Math.floor(Math.random()*28),
Math.floor(Math.random()*25),
Math.floor(Math.random()*60),
Math.floor(Math.random()*60),
Math.floor(Math.random()*1000)
);
我想将此日期保存为字符串,然后将其转换回日期
我用
var time_for_save = time.toUTCString();
这给了我这样的字符串:
Sat, 01 Oct 2011 07:42:38 GMT
如何将这个日期转换回 Date 对象?
或者是否有更好的方法通过字符串保存/检索日期对象?
最佳答案
给定日期字符串表示,您可以使用 Date.parse函数获取“日期字符串与 1970 年 1 月 1 日午夜之间的毫秒数”。之后,您可以使用日期构造函数从“纪元毫秒”获取新的日期对象。
var date = new Date(Date.parse(time_for_save));
关于javascript - 从 toUTCString() 开始的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7318288/
我从网络服务返回一个 JSON 字符串。我也在 W3C 学校网站上为我们的本地计算机测试了同样的东西。我通过 Javascript 从 UTC 字符串返回服务和 W3C 站点的时间提前了 2 小时。有
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
我在下个月的随机日期创建随机时间,这样 var time = new Date(now.getFullYear(), now.getMonth() + 1,
我正在将数据保存在 MongoDB 中服务器来自 Node.js应用程序(使用 Mongoose )。 考虑以下代码: var mongoose = require('mongoose'); var
我需要得到如下格式 2015 年 8 月 19 日 04:22:36 GMT 我有以下代码 var dt = '2015-08-19 04:22:36'; alert(new Date(dt).toU
如何在 Javascript 上将 python 结果作为 new Date().toUTCString() 获取? 在我制作的 Javascript 上: new Date().toUTCStrin
在我的 React 应用程序中,日期组件的 .toUTCString() 将其时区显示为“GMT”。这是错误的——格林威治标准时间与 UTC 不同:GMT 是时区,UTC 是时间标准,而且该方法字面上
我知道如何将 new Date() 更改为 UTC 时间new Date().toUTCString()但我想更进一步,获取 UTC 时间,然后将其更改为 1970 年 1 月 1 日以来的毫秒数。
我是一名优秀的程序员,十分优秀!