In Java we can do it like this:
new Date(10L);
That's 10 milliseconds since 1 January 1970 UTC.
Per the MDN docs it does not look like Javascript has a similar constructor. Do we need to do something like:
new Date(0,0,0,0,0,0,10);
In Java we can do it like this:
new Date(10L);
That's 10 milliseconds since 1 January 1970 UTC.
Per the MDN docs it does not look like Javascript has a similar constructor. Do we need to do something like:
new Date(0,0,0,0,0,0,10);
Not that hard:
new Date(10);
The C-style L
postfix is not a JavaScript feature, but otherwise Date()
works as expected.
One of the constructor methods is:
new Date(value);
Where value
is specifically defined as:
Integer value representing the number of milliseconds since January 1, 1970, 00:00:00 UTC, with leap seconds ignored (Unix Epoch; but consider that most Unix timestamp functions count in seconds).
This is exactly what you're looking for, so it works just like you'd expect from Java.