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

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

黄舟
黄舟Original
2017-11-07 10:12:562089browse

Definition and usage

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

Syntax

dateObject.setDate(day)
Parameters Description
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>

Output:

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

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>

This will produce the following results:

Sun Aug 24 23:30:00 UTC+0530 2008


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!

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