![]() |
VOOZH | about |
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.
DateObj.getSeconds()This function does not accept any parameter.
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.
Output:
32Example 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.
Output:
NaNExample 3: If a second is not given, it returns zero (0).
Output:
0Example 4: If nothing as a parameter is given to the Date() constructor, it returns the current second.
Output:
8Example 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.
Output:
0We have a complete list of Javascript Javascript Date methods, to check those please go through the Javascript Date Object Complete Reference article.
The getSeconds() method returns the seconds (0–59) of a specified date according to local time.
You use it by calling the method on a Date object:
let seconds = new Date().getSeconds(); // Example output: 42
It returns a number representing the seconds (from 0 to 59) of the specified 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