As you might know, you can display the time in JavaScript by doing Date()
But can you display the Linux Epoch time in JavaScript?
I would like to know because I have a time converter and It would be nice to show the current Epoch time.
As you might know, you can display the time in JavaScript by doing Date()
But can you display the Linux Epoch time in JavaScript?
I would like to know because I have a time converter and It would be nice to show the current Epoch time.
You have to use the .getTime()
method of the Date
object.
var d = new Date();
alert(d.getTime());
Epoch is also called timestamp
.
Simple and straightforward.
var milliseconds = new Date().getTime();
Older browsers:
(new Date).getTime()
New way:
Date.now()
Returns in milliseconds, so epoch / 1000 | 0
to get seconds.