Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In JavaScript how to get second of current day? [closed]

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

like image 962
Kirill Titov Avatar asked Jul 12 '12 07:07

Kirill Titov


People also ask

How to get seconds in javascript date?

JavaScript Date getSeconds() getSeconds() returns the seconds (0 to 59) of a date.

What is getSeconds in Javascript?

getSeconds() The getSeconds() method returns the seconds in the specified date according to local time.

How could you write a method on instance of a date which will give you next day?

var dt = new Date(); dt. setTime(dt. getTime() + (24 * 60 * 60 * 1000));


1 Answers

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())));
like image 88
T.J. Crowder Avatar answered Nov 07 '22 14:11

T.J. Crowder