.getUTCSeconds()
Published Jun 17, 2023
Contribute to Docs
The getUTCSeconds()
method returns the seconds (ranging from 0 to 59) of a specific date according to UTC (Coordinated Universal Time).
Syntax
Date.getUTCSeconds()
A Date
object is used for working with dates and times. The object provides a way to create, manipulate, and format dates in various formats.
A Date
object can be created by declaring a new variable with the new Date()
constructor.
Example
The following example uses the .getUTCSeconds()
method to get the seconds of 2023-06-06T10:30:04
and logs the result to the console:
const date = new Date('2023-06-06T10:30:04');const seconds = date.getUTCSeconds();console.log(seconds);
This example results in the following output:
4
Codebyte Example
The codebyte example below uses the .getUTCSeconds()
method to get the current time in seconds and logs it to the console:
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.