In JavaScript how to get second of current day?

Kirill Titov picture Kirill Titov · Jul 12, 2012 · Viewed 12.7k times · Source

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

Answer

T.J. Crowder picture T.J. Crowder · Jul 12, 2012

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())));