Home > Web Front-end > JS Tutorial > The JavaScript method setUTCDate() sets the day of the month according to Universal Time (UTC)

The JavaScript method setUTCDate() sets the day of the month according to Universal Time (UTC)

黄舟
Release: 2017-11-07 14:14:39
Original
1769 people have browsed it

Definition and Usage

The setUTCDate() method is used to set a day of the month based on Universal Time (UTC).

Syntax

dateObject.setUTCDate(day)
Copy after login
ParametersDescription
day A certain day in , expressed in universal time. This parameter is an integer between 1 ~ 31.

Return value

Adjusted date expressed in milliseconds.

Tips and Notes:

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 day field of the current month to 15 through the setUTCDate() method:

<script type="text/javascript">

var d = new Date()
d.setUTCDate(15)
document.write(d)

</script>
Copy after login

Output:

Wed Nov 15 2017 14:11:35 GMT+0800 (中国标准时间)
Copy after login

If the specified parameter is outside the expected range, calling setUTCDate attempts to update the latest information of the Date object accordingly.

Example:

<html>
<head>
<title>JavaScript setUTCDate Method</title>
</head>
<body>
<script type="text/javascript">
  var dt = new Date( "Aug 28, 2008 23:30:00" );
  dt.setUTCDate( 20 );
  document.write( dt ); 
</script>
</body>
</html>
Copy after login

This will produce the following results:

Wed Aug 20 23:30:00 UTC+0530 2008
Copy after login


The above is the detailed content of The JavaScript method setUTCDate() sets the day of the month according to Universal Time (UTC). 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