admin管理员组文章数量:1186459
I'm trying to write a javascript function that calculates the time since Oct 11th, 1910 so I can throw it into a timer for a project I'm working on. I get that javascript's milliseconds works from epoc, but I don't and can't find a way to get the milliseconds since a date earlier than 01.01.1970
Does anyone have any loose code that can do the above that they may be willing to share?
I'm trying to write a javascript function that calculates the time since Oct 11th, 1910 so I can throw it into a timer for a project I'm working on. I get that javascript's milliseconds works from epoc, but I don't and can't find a way to get the milliseconds since a date earlier than 01.01.1970
Does anyone have any loose code that can do the above that they may be willing to share?
Share Improve this question asked Oct 1, 2009 at 0:29 RobbyRobby 3 |3 Answers
Reset to default 21
var oldGoodTimes = new Date(1910, 9, 11); // January = 0
var actualDate = new Date();
console.log(actualDate.getTime() - oldGoodTimes.getTime());
Try this:
var yeOldeTimes = new Date();
yeOldeTimes.setFullYear(1910, 9, 11);
var myNewDate = new Date();
console.log("Milliseconds since Ye Olde Times: " + (myNewDate - yeOldeTimes));
Number of milliseconds since Oct 11th, 1910
console.log(new Date() - new Date('1910', '10', '11'))
// new Date().valueOf() - milliseconds since 1970
// -(new Date('1910', '10', '11')).valueOf() - milliseconds from 1910 since 1970
本文标签: javascriptDates before Jan 01 1970Stack Overflow
版权声明:本文标题:javascript - Dates before Jan. 01 1970? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738346400a2078148.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
new Date(8.64e+15)
ornew Date(-8.64e+15)
you'll still get valid dates. But the date parsers on v8 (Chrome, node, deno) and Firefox can only handle four digit values for year that's why your date shows Invalid Date. On jsc (Safari, bun), it actually handles all possible year values and that statement gives valid date there. – brc-dd Commented Sep 23, 2024 at 13:55