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

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

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

 javascript Date.setFullYear()方法按照本地时间的将指定全年的日期。
语法

Date.setFullYear(yearValue[, monthValue[, dayValue]])

注:括号内的参数是可选

下面是参数的详细信息:

  •     yearValue : 一个整数,指定年份的数字值,例如,2008年
  •     monthValue : 从0到11的整数表示的月份一月到十二月
  •     dayValue : 1到31之间的整数,表示一个月的一天。如果指定dayValue参数,则还必须指定monthValue

如果不指定monthValue和dayValue参数,那么getMonth和getDate方法返回的值被使用
返回值:

  • NA

例子:

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

这将产生以下结果:

Mon Aug 28 23:30:00 UTC+0530 2000 

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