当前位置: 首页 > 网络学院 > 客户端脚本教程 > JavaScript > JavaScript setYear()方法

JavaScript
JS 介绍
JS 怎样使用
JS 在哪使用
JS 变量
JS If...Else
JS Switch
JS 操作符
JS Popup Boxes
JS 函数
JS For 循环
JS While 循环
JS Break 循环
JS For...In
JS 事件
JS Try...Catch
JS Throw
JS onerror
JS 特殊字符
JS Guidelines
JS 对象介绍

JavaScript setYear()方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 325 ::
收藏到网摘: n/a

Definition and Usage
定义与用法

The setYear() method is used to set the year.
setYear()方法可用来设置年份

Syntax
语法

dateObject.setYear(year)

Parameter
参数
Description
描述
year Required. A two or four digit number that indicates the year
必选。一个两位或是四位数字,代表了年份


Tips and Notes
提示与注意点

Note: If the year parameter is a two-digit number, like setYear(91), it will be perceived as 1991. To specify a year before 1900 or after 1999, always use four digits!
注意点:如果参数是个两位数字,比如setYear(91),那么可以理解为是1991年。如要指定1900年以前或是1999年以后的年份,那么就必须使用四位数了!

Note: This method is always used in conjunction with a Date object.
注意:这个方法得结合Date对象使用

Important: The setYear() method should no longer be used. Use the setFullYear() method instead!!
重要信息:setYear()方法不应该再用下去了。得开始用setFullYear()方法了


Example
举例

In this example we set the year to 1891 with the setYear() method:
在这个举例中我们使用了setYear()方法将年份设置为1891年:

<script type="text/javascript">
var d = new Date()
d.setYear(1891)
document.write(d)
</script>

The output of the code above will be:
输出结果为:



Try-It-Yourself Demos
尝试与演示

setYear()
How to use setYear() to set the year.
怎样使用setYear()来设置年份

评论 (0) All

登陆 | 还没注册?