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
.
简单明了。
var milliseconds = new Date().getTime();
Older browsers:
(new Date).getTime()
New way:
Date.now()
Returns in milliseconds, so epoch / 1000 | 0
epoch / 1000 | 0
to get seconds.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.