1. 程式人生 > >JavaScript(八)日期對象

JavaScript(八)日期對象

相同 color date() 需要 分鐘 圖片 div new 換算

Date對象

1.創建方式

var now = new Date(); //現在返回的直接就是 當前的時間  不需要進行換算了 

       

返回格式

技術分享圖片 (星期 月 日 年 時 分 秒 時區)

2.日期的格式化方法

  dateObject.toDateString();  返回 星期 月 日 年

  dateObject.toTimeString();  返回 時 分 秒 時區

3.日期時間組建方法  dateObject.function();

getTime() 返回從1970至今的毫秒數(valueOf()相同) setTime() 設置從1970至今的毫秒數 從而達到改變日期的效果
getFullYear() 獲取4位數年份 setFullYear() 設置年份,改變日期對象的毫秒數
getMonth() 獲取月份(從0開始,所以要加一 就是當前月份) setMonth()  設置月份(超出加年)
getDate() 獲取幾號 setDate() 設置幾號(超出加月)
getDay() 獲取星期 日-六 對應 0-6
getHours() 獲取小時 setHours() 設置小時(超24加天)
getMinutes() 獲取分鐘 setMinutes() 設置分鐘
getSeconds() 獲取秒數 setSeconds() 設置秒數
getMilliseconds() 獲取毫秒數 setMilliseconds() 設置毫秒數

JavaScript(八)日期對象