Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 15:55:39
Original
2025 people have browsed it

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

Date.setYear(yearValue)

Copy after login

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

下面是参数的详细信息:

  • 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>

Copy after login

这将产生以下结果:

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

Copy after login

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!