前端獲取當前的時間(年月日,周,時分秒),一點點詳細哦。

首先獲取本地時間,然後對其進行針對性取值即可,如下:

<script>
    let date = new Date();
    let dateYear = date.getFullYear();             //獲取年 
    let dateMonth = date.getMonth();               //獲取月  
    let dateDate = date.getDate();                 //獲取當日
    let dateDay = date.getDay();                   //獲取當日星期數
    let dateHours = date.getHours()                //獲取小時
    let dateMinutes = date.getMinutes()            //獲取分鐘
    let dateSeconds = date.getSeconds()            //獲取秒
    let dateMilliseconds = date.getMilliseconds()  //獲取毫秒
</script>

需要注意區分getDate()getDay()這兩個API,以上就是對當前時間的獲取及操作。

巴拉巴拉:

==主頁傳送門==

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章