getfullyear是用来获取年份,返回一个表示年份的 4 位数字,而setfullyear用来设置年份,也可以用来设置具体的日期。从具体到日期提取年份:<script type="text/javascript">
var born = new Date("July 21, 1983 01:15:00")
document.write("I was born in " + born.getFullYear())
</script>
输出:
I was born in 1983通过 setFullYear() 把日期设置为 November 01, 2016:<script type="text/javascript">
var d = new Date()
d.setFullYear(2016,10,1)
document.write(d)
</script>
输出:
Tue Nov 01 2016 11:55:23 GMT+0800 (中国标准时间)