JavaScript getUTCFullYear() 方法
定義和用法
getUTCFullYear() 方法可返回根據(jù)世界時(shí) (UTC) 表示的年份的四位數(shù)字。
語法
dateObject.getUTCFullYear()
返回值
返回 dateObject 用世界時(shí)表示時(shí)的年份,該值是一個(gè)四位的整數(shù),而不是兩位數(shù)的縮寫。
提示和注釋:
注釋:該方法總是結(jié)合一個(gè) Date 對(duì)象來使用。
提示:有關(guān)通用協(xié)調(diào)時(shí)間 (UTC) 的更多資料,請(qǐng)參閱百度百科。
實(shí)例
例子 1
In this example we get the current year and print it:
<script type="text/javascript"> var d = new Date() document.write(d.getUTCFullYear()) </script>
輸出:
例子 2
Here we will extract the year out of the specific date:
<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
TIY
- 以不同的格式顯示 UTC 日期
- 如何使用 getUTCDate(), getUTCMonth() 以及 getUTCFullYear() 來使用不同的格式顯示 UTC 日期。