.getSeconds()
Anonymous contributor
Anonymous contributor5 total contributions
Anonymous contributor
Published Jun 22, 2021Updated Jun 5, 2023
Contribute to Docs
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.
All contributors
- Anonymous contributorAnonymous contributor5 total contributions
- christian.dinh2476 total contributions
- Anonymous contributorAnonymous contributor3071 total contributions
- EugeneGoh_51 total contributions
- Anonymous contributor
- christian.dinh
- Anonymous contributor
- EugeneGoh_
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.