DIV CSS 佈局教程網

JavaScript 日期函數整理:年月日、時分秒與格式化
編輯:關於JavaScript     

日期取值

new Date() 可建立日期物件。getFullYear 取得四位年份,getMonth 取得月份,範圍 0 到 11,getDate 取得日,getDay 取得星期。

var now = new Date();
now.getFullYear();
now.getMonth() + 1;
now.getDate();
now.getDay();

時間取值

getHours、getMinutes、getSeconds、getMilliseconds 可取得時分秒與毫秒。getTime 可取得從 1970 年起的毫秒數。

設定日期

setFullYear、setMonth、setDate、setHours、setMinutes、setSeconds 可設定日期與時間。

格式化

toLocaleDateString、toLocaleTimeString、toLocaleString 可輸出當地日期與時間格式。

注意

月份從 0 開始,星期從 0 開始且通常 0 表示星期日。建立日期時若省略參數,會使用目前日期時間。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved