Last Updated : 11 Jul, 2025
The date.getSeconds() method is used to fetch the seconds from the given Date object according to the local time. The value returned by this method ranges from 0 to 59.
Syntax:DateObj.getSeconds()Parameters:
This function does not accept any parameter.
Return Values:It returns the second for the given date object. Seconds is an integer value ranging from 0 to 59.
Example 1: Below is an example of Date.getSeconds() method.
javascript
// Here a date has been assigned
// while creating Date object
let DateObj = new Date('October 15, 1996 05:35:32');
// second from above Date object is being
// extracted using getSeconds()
let sec = DateObj.getSeconds();
// Printing second
console.log(sec);
Output:
32
Example 2: Here the date of the month should lie between 1 to 31 because none of the months have a date greater than 31 that is why it returns NaN i.e, not a number because if the date for the month does not exist.
javascript
// Here a date has been assigned
// while creating Date object
let DateObj = new Date('October 33, 1996 05:35:32');
// second from above Date object is being
// extracted using getSeconds()
let sec = DateObj.getSeconds();
// Printing second
console.log(sec);
Output:
NaN
Example 3: If a second is not given, it returns zero (0).
javascript
// Here a date has been assigned
// while creating Date object
let DateObj = new Date('October 13, 1996 05:35');
// second from above Date object is being
// extracted using getSeconds()
let sec = DateObj.getSeconds();
// Printing second
console.log(sec);
Output:
0
Example 4: If nothing as a parameter is given to the Date() constructor, it returns the current second.
javascript
// Creating a Date Object
let DateObj = new Date();
// second from above Date object is being
// extracted using getSeconds()
let sec = DateObj.getSeconds();
// Printing second
console.log(sec);
Output:
8
Example 5: If the second is 88, it returns 0 as an exception because the second's range is between 0 to 59, and 88 is out of this range.
javascript
// Here a date has been assigned
// while creating Date object
let DateObj = new Date('October 13, 1996 05:35:88');
// Second from above Date object is being
// extracted using getSeconds()
let sec = DateObj.getSeconds();
// Printing second
console.log(sec);
Output:
0
We have a complete list of Javascript Javascript Date methods, to check those please go through the Javascript Date Object Complete Reference article.
Supported Browsers:How do you use the getSeconds() method?The getSeconds() method returns the seconds (0–59) of a specified date according to local time.
What type of value does getSeconds() return?You use it by calling the method on a Date object:
let seconds = new Date().getSeconds(); // Example output: 42
Does getSeconds() account for time zones?It returns a number representing the seconds (from 0 to 59) of the specified date.
Can getSeconds() be used to get the seconds from a past or future date?Yes, it returns the seconds based on the local time zone of the environment where the code is executed.
Yes, you can create a Date object for any past or future date and call getSeconds() on it to get the seconds:
let pastDate = new Date('2000-01-01T00:00:30');
let seconds = pastDate.getSeconds(); // Returns 30
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4