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

JavaScript
JS 字符串
JS Date
JS数组,JS Array
JS Boolean
JS Math
JS HTML DOM
JS Browser
JS Cookies
JS 校验
JS Animation
JS Image Maps
JS Timing
JS 建立对象
JS 摘要
JS 实例
JS 对象实例
JS DOM 实例
JS数组对象参考
JS布尔对象参考
JS日期对象参考

JavaScript setYear()方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 327 ::
收藏到网摘: 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

登陆 | 还没注册?