I am trying to convert a decimal number to a date object in Javascript. I have tried multiple methods and using moment, but all my conversions are wrong. An example of a value I want to convert is 705623516.402048. I have tried to interpret the int part as seconds and the decimal part as milliseconds, but it has gone wrong too.
I cannot use JQuery, just plain JS or moment
Any help is greatly appreciated
Thanks in advance
2
Answers
If that’s supposed to be today’s date, it looks like it’s seconds since 2001-01-01. So you can use
Date.setSeconds()
to add to that date.The time value appears to be microseconds. Based on Barmar’s answer, you can maintain millisecond precision (the best ECMAScript Dates can do currently) using:
Date epochs are typically UTC (though not certainly), hence the use of Date.UTC.