Reputation:
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?
Upvotes: 14
Views: 18901
Reputation: 1060
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
Upvotes: 0
Reputation: 546303
Try this:
var yeOldeTimes = new Date();
yeOldeTimes.setFullYear(1910, 9, 11);
var myNewDate = new Date();
console.log("Milliseconds since Ye Olde Times: " + (myNewDate - yeOldeTimes));
Upvotes: 3
Reputation: 4395
var oldGoodTimes = new Date(1910, 9, 11); // January = 0
var actualDate = new Date();
console.log(actualDate.getTime() - oldGoodTimes.getTime());
Upvotes: 21