Method
JavaScript Date getUTCSeconds() Method
The JavaScript Date getUTCSeconds() method is used to get the seconds of the date object, according to universal time. The syntax for the method is given below.
[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
Date.getUTCSeconds();
[/dm_code_snippet]
The getUTCSeconds() method returns an integer between 0 and 59.
Examples of JavaScript Date getUTCSeconds() Method
Example 1: This example uses the getUTCSeconds() method to get the current second in universal time.
[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
// Create a new date object var date = new Date(); // Print the current second in universal time document.write("Current second in universal time: " + date.getUTCSeconds());
[/dm_code_snippet]
Output:
[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
Current second in universal time: 59
[/dm_code_snippet]
Example 2: This example uses the getUTCSeconds() method to get the second of a given date in universal time.
[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
// Create a new date object var date = new Date("July 20, 2020 13:20:30"); // Print the second of the given date in universal time document.write("Second of the given date in universal time: " + date.getUTCSeconds());
[/dm_code_snippet]
Output:
[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
Second of the given date in universal time: 30
[/dm_code_snippet]