Alice Alice - 8 months ago 33
Javascript Question

How can I get seconds since epoch in Javascript?

On Unix, I can run

date '+%s'
to get the amount of seconds since epoch. But I need to query that in a browser front-end, not back-end.

Is there a way to find out seconds since Epoch in JavaScript?

var seconds = new Date() / 1000;

Or, for a less hacky version:

var d = new Date();
var seconds = d.getTime() / 1000;