Home  >  Article  >  Web Front-end  >  The JavaScript method setUTCSeconds() sets the seconds of a specified time based on Universal Time (UTC)

The JavaScript method setUTCSeconds() sets the seconds of a specified time based on Universal Time (UTC)

黄舟
黄舟Original
2017-11-08 10:00:131623browse

Definition and Usage

The setUTCSeconds() method is used to set the seconds of the specified time based on Universal Time (UTC).

Syntax

dateObject.setUTCSeconds(sec,millisec)
Parameters Description
sec

Required. The value of the seconds field to set for the dateObject. Expressed using world time.

This parameter is an integer between 0 ~ 59.

millisec

Optional. The value of the milliseconds field to set for the dateObject. Expressed using world time.

This parameter is an integer between 0 ~ 999.

Return value

Adjusted date expressed in milliseconds.

Tips and Notes:

Note: If one of the above parameters is specified using a one-digit number, then JavaScript will be included in the result Add one or two leading zeros.

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

In this example, we will set the seconds field of the current time to 01 through setUTCSeconds():

<script type="text/javascript">

var d = new Date()
d.setUTCSeconds(1)
document.write(d)

</script>

Output:

Wed Nov 08 2017 09:59:01 GMT+0800 (中国标准时间)

If the specified argument is outside the expected range, calling setUTCSeconds attempts to update the latest information for the Date object accordingly. For example, if secondsValue uses 100, the minutes stored in the date object will be incremented by 1, and 40 will be used for seconds.

Example:

<html>
<head>
<title>JavaScript setUTCSeconds Method</title>
</head>
<body>
<script type="text/javascript">
  var dt = new Date( "Aug 28, 2008 13:30:00" );
  dt.setUTCSeconds( 65 );
  document.write( dt ); 
</script>
</body>
</html>

This will produce the following results:

Thu Aug 28 13:31:05 UTC+0530 2008

The above is the detailed content of The JavaScript method setUTCSeconds() sets the seconds of a specified time based on Universal Time (UTC). For more information, please follow other related articles on the PHP Chinese website!

Statement:
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