Home > Web Front-end > JS Tutorial > JavaScript method setDate() to set a certain day of the month

JavaScript method setDate() to set a certain day of the month

黄舟
Release: 2017-11-07 10:12:56
Original
2162 people have browsed it

Definition and usage

setDate() method is used to set a certain day of the month.

Syntax

dateObject.setDate(day)
Copy after login
ParametersDescription
day Required. A numerical value (1 ~ 31) representing a day of the month.

Return value

Adjusted date expressed in milliseconds. Before ECMAScript was standardized, this method returned nothing.

Tips and Notes:

Note: This method is always used in conjunction with a Date object.

Example

In this example, we will set the day of the current month to 15 through the setDate() method:

<script type="text/javascript">

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

</script>
Copy after login

Output:

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

Example:

The second statement below changes from the original value to August 24.

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

This will produce the following results:

Sun Aug 24 23:30:00 UTC+0530 2008
Copy after login


The above is the detailed content of JavaScript method setDate() to set a certain day of the month. 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