JS工具對象 DATE 方法

來源:互聯網
上載者:User

標籤:style   擷取   工具   pre   span   bsp   class   eth   minutes   

1.擷取當前電腦的系統時間   var time = new Date();

var time = new Date();//擷取當前系統時間
console.log(time); // Mon Apr 03 2017 09:03:18 GMT+0800 (中國標準時間)

2.擷取當前年    time.getFullYear();

var time = new Date();var year = time.getFullYear();console.log(year);//2017

3.擷取當前月   time.getMonth();

var time = new Date();var month = time.getMonth();console.log(month); //3

4.擷取當前天 time.getDate();

var time = new Date();var day = time.getDate();console.log(day);3

5.擷取當前 (0-6代表周日-周六)time.getDay();

var time = new Date();var week = time.getDay();console.log(week); //  1  (結果 0-6 周日、周一、周二...周六 )

6.擷取目前時間(當前小時整點) time.getHours();

var time = new Date();var hours = time.getHours();console.log("hours   "+hours);//  10

7.擷取當前分鐘(分鐘) time.getMinutes();

var time = new date();var minutes = time.getMinutes();console.log(minutes); //34

8.擷取當前秒 time.getSeconds();

var  time = new date();var  seconds = time.getSeconds();console.log(seconds);

9.擷取當前毫秒 time.getMilliseconds();

var time = new Date();var mlSeconds = time.getMilliseconds();console.log("miSeconds       "+mlSeconds);//  519

10.

JS工具對象 DATE 方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.