Home  >  Article  >  Web Front-end  >  在JavaScript中操作时间之setYear()方法的使用_基础知识

在JavaScript中操作时间之setYear()方法的使用_基础知识

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

 javascript Date.setYear()方法按照通用时间设置指定年份。
语法

Date.setYear(yearValue)

注:括号内的数据是可选的

下面是参数的详细信息:

  •     yearValue : 一个整数值。

返回值:

  • NA

例子:

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

这将产生以下结果:

Mon Aug 28 13: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