方法:
getYear() | 取得年份 {year - 1900 [ = e.g. 97]} | getFullYear() | 取得完整四位數年份 | getMonth() | 取得月份 {[一月] 0 - [十二月] 11} | getDate() | 取得一個月的一天 {1 - 31} | getDay() | 取得一個星期的一天 {[星期日] 0 - [星期六] 6} | getHours() | 取得鐘頭 {0 - 23} | getMinutes() | 取得分鐘 {0 - 59} | getSeconds() | 取得秒數 {0 - 59} | getTime() | 取得時間 {由 1970年1月1日零時零分計起 (單位:微秒) } | setYear(date_var) | 設定年份 {year - 1900 [= e.g. 97]} | setFullYear(yyyy) | 設定某一年年份 | setMonth(date_var) | 設定月份 {0 - 11} | setDate(date_var) | 設定一個月的一天 {1 - 31} | setHours(date_var) | 設定小時 {0 - 23} | setMinutes(date_var) | 設定分鐘 {0 - 59} | setSeconds(date_var) | 設定秒數 {0 - 59} | setTime(date_var) | 設定時間 {由 1970年1月1日0時0分計起 (單位:微秒) } |
範例語法:
<script> function showTime(line) { document.write(line + "<br>") }
var now = new Date() showTime( "年: " + (now.getYear()+1900) ) showTime( "月: " + (now.getMonth()+1) ) showTime( "日: " + now.getDate() ) showTime( "星期: " + now.getDay() ) showTime( "時: " + now.getHours() ) showTime( "分: " + now.getMinutes() ) showTime( "秒: " + now.getSeconds() ) showTime( "Long型態時間: " + now.getTime() ) </script>
|
|