Home > Article > Web Front-end > JavaScript can return the time seconds method getUTCSeconds() based on universal time
Definition and Usage
getUTCSeconds() method returns the seconds of time based on universal time.
Syntax
dateObject.getUTCSeconds()
Return value
When dateObject is expressed in universal time, return its seconds field, which is an integer between 0 ~ 59 .
Tips and Notes:
Note: The value returned by getUTCSeconds() is a two-digit number. However, the return value is not always two digits, if the value is less than 10, only one digit is returned.
Note: This method is always used in conjunction with a Date object.
Tip: For more information about Universal Coordinated Time (UTC), please refer to Baidu Encyclopedia.
Example
Example 1
In this example, we will get the UTC seconds of the current time:
<script type="text/javascript"> var d = new Date() document.write(d.getUTCSeconds()) </script>
Output:
8
Example 2
Here we will extract UTC seconds from a specific date and time:
<script type="text/javascript"> var Birthday = new Date("July 21, 1983 01:15:00") document.write(Birthday.getUTCSeconds()) </script>
Output:
0
Example:
The following example prints the current time to the seconds part of the variable hrs.
<html> <head> <title>JavaScript getUTCSeconds Method</title> </head> <body> <script type="text/javascript"> var dt = new Date(); document.write("getUTCSeconds() : " + dt.getUTCSeconds() ); </script> </body> </html>
This will produce the following results
getUTCSeconds() : 14
The above is the detailed content of JavaScript can return the time seconds method getUTCSeconds() based on universal time. For more information, please follow other related articles on the PHP Chinese website!