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 表示星期日。建立日期時若省略參數,會使用目前日期時間。