getUTCFullYear() 方法可返回根据世界时 (UTC) 表示的年份的四位数字。
dateObject.getUTCFullYear()
返回 dateObject 用世界时表示时的年份,该值是一个四位的整数,而不是两位数的缩写。
在本例中我们获得并输出当前年份:
<script type="text/javascript"> var d = new Date() document.write(d.getUTCFullYear()) </script>
输出:
在本例中我们从具体的日期中提取年份:
<script type="text/javascript"> var born = new Date("July 21, 1983 01:15:00") document.write("I was born in " + born.getUTCFullYear()) </script>
输出:
I was born in 1983