Home > Web Front-end > JS Tutorial > body text

JavaScript can return the time seconds method getUTCSeconds() based on universal time

黄舟
Release: 2017-11-07 09:53:45
Original
1012 people have browsed it

Definition and Usage

getUTCSeconds() method returns the seconds of time based on universal time.

Syntax

dateObject.getUTCSeconds()
Copy after login

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>
Copy after login

Output:

8
Copy after login

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>
Copy after login

Output:

0
Copy after login

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>
Copy after login

This will produce the following results

getUTCSeconds() : 14
Copy after login


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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template