THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

JavaScript getSeconds() Method

Date Object Reference JavaScript Date Object

Example

Return the seconds, according to local time:

var d = new Date();
var n = d.getSeconds();

The result of n could be:

Try it yourself »

More "Try it Yourself" examples below.


Definition and Usage

The getSeconds() method returns the seconds (from 0 to 59) of the specified date and time.


Browser Support

Method
getSeconds() Yes Yes Yes Yes Yes

Syntax

Date.getSeconds()

Parameters

None

Technical Details

Return Value: A Number, from 0 to 59, representing the seconds
JavaScript Version: 1.0

Examples

More Examples

Example

Using getHours(), getMinutes(), and getSeconds() to display the time:

function addZero(i) {
    if (i < 10) {
        i = "0" + i;
    }
    return i;
}

function myFunction() {
    var d = new Date();
    var x = document.getElementById("demo");
    var h = addZero(d.getHours());
    var m = addZero(d.getMinutes());
    var s = addZero(d.getSeconds());
    x.innerHTML = h + ":" + m + ":" + s;
}
Try it yourself »

Date Object Reference JavaScript Date Object