Home  >  Article  >  Web Front-end  >  JavaScript中setMonth()方法的使用详解_基础知识

JavaScript中setMonth()方法的使用详解_基础知识

WBOY
WBOYOriginal
2016-05-16 15:55:421252browse

 javascript Date.setMonth()方法按照本地时间设置每月指定日期。
语法

Date.setMonth(monthValue[, dayValue])

注:括号内外观和数据是可选的

下面是参数的详细信息:

  •     monthValue : 从0到11的整数(表示个月份,从一月到十二月)。
  •     dayValue : 从1到31的整数,代表一个月中的某天。
  •     msValue : 一个数字0和999之间,表示毫秒。如果指定msValue参数,则还必须指定minutesValue和secondsValue。

如果不指定dayValue参数,那么使用从getDate方法返回的值。如果指定的参数是预期范围之外,setMonth尝试相应地更新Date对象的最新信息。例如,如果使用monthValue为15,year将增加1(year + 1)的增量,和3将被用于月份的值。
返回值:

  • NA

例子:

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

这将产生以下结果:

Fri Mar 28 23:30:00 UTC+0530 2008 

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