JavaScript .getSeconds()
Anonymous contributor
Published Jun 22, 2021Updated Jun 5, 2023
Called from an instance of the Date class, will return the seconds according to the local time.
Syntax
myDate.getSeconds();
The return value of getSeconds() will only be an integer number between 0 and 59, meaning seconds.
Example
To determine if the match has ended or still ongoing:
const today = new Date('June 25, 2021 13:41:50');if (today.getSeconds() > 50) {console.log('The match has ended.');} else {console.log('This match is still ongoing.');}// Output: This match is still ongoing.
Codebyte Example
The example below defines a new Date object dateTimeNow, and then saves the result of the getSeconds() method in a new variable seconds. Finally, the current date\time, the current seconds, and the seconds remaining in the current minute are logged to the console.
Learn JavaScript on Codecademy
- Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
- Includes 34 Courses
- With Professional Certification
- Beginner Friendly.115 hours
- Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
- Beginner Friendly.15 hours