JavaScript(八)日期對象

來源:互聯網
上載者:User

標籤:bubuko   idt   返回   object   需要   技術   min   mil   ima   

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(八)日期對象

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.