Frage

So the question is described in title. I need to get current second of the day using JavaScript.

War es hilfreich?

Lösung

You add up the bits:

var dt = new Date();
var secs = dt.getSeconds() + (60 * dt.getMinutes()) + (60 * 60 * dt.getHours());

or if you prefer

var dt = new Date();
var secs = dt.getSeconds() + (60 * (dt.getMinutes() + (60 * dt.getHours())));

Andere Tipps

For example (in action):

​var today = new Date(), today_abs = new Date(), today_secs = 0;
today_abs.setHours(0);
today_abs.setMinutes(0);
today_abs.setSeconds(0);
today_secs = (today.getTime() - today_abs.getTime()) / 1000;​
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top