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

JavaScript method getSeconds() that returns time seconds

黄舟
Release: 2017-11-06 10:05:01
Original
2257 people have browsed it

Definition and Usage

getSeconds() method returns the seconds of time.

Syntax

dateObject.getSeconds()
Copy after login

Return value

The minute field of dateObject, displayed in local time. The return value is an integer between 0 ~ 59.

Tips and Notes:

Note: The value returned by getSeconds() 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.

Example

Example 1

In this example, we can get the seconds of the current time:

<script type="text/javascript">

var d = new Date()
document.write(d.getSeconds())

</script>
Copy after login

Output:

37
Copy after login

Example 2

In this example, we will extract the seconds field from the specific date and time:

<script type="text/javascript">

var Birthday = new Date("July 21, 1983 01:15:00")
document.write(Birthday.getSeconds())

</script>
Copy after login

Output:

0
Copy after login

javascript Date.getSeconds() method Returns seconds on the specified date in local time. The value returned by getSeconds is an integer between 0 and 59.

Returns the number of seconds on the specified date according to local time.
Example:

<html>
<head>
<title>JavaScript getSeconds Method</title>
</head>
<body>
<script type="text/javascript">
  var dt = new Date( "December 25, 1995 23:15:20" );
  document.write("getSeconds() : " + dt.getSeconds() ); 
</script>
</body>
</html>
Copy after login

This will produce the following results:

getSeconds() : 20
Copy after login


The above is the detailed content of JavaScript method getSeconds() that returns time seconds. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!