JavaScript Date getSeconds() Method
- Previous Page getMonth()
- Next Page getTime()
- Go to Parent Layer JavaScript Date Reference Manual
Definition and Usage
getSeconds()
The method returns the number of seconds (from 0 to 59) for a specified date and time.
Example
Example 1
Return the number of seconds based on local time:
var d = new Date(); var n = d.getSeconds();
Example 2
Display time using getHours(), getMinutes(), and getSeconds():
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; }
Syntax
Date.getSeconds()
Parameters
No parameters.
Technical Details
Return Value: | Numeric value, ranging from 0 to 59, representing seconds. |
---|---|
JavaScript Version: | ECMAScript 1 |
Browser Support
Method | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
getSeconds() | Support | Support | Support | Support | Support |
Related Pages
Tutorial:JavaScript Date
Tutorial:JavaScript Date Format
Tutorial:JavaScript Object Constructor
- Previous Page getMonth()
- Next Page getTime()
- Go to Parent Layer JavaScript Date Reference Manual