1. <script>
    2. var date= new Date();
    3. /* 年月日 */
    4. console.log(date)
    5. var year = date.getFullYear();
    6. console.log(year)
    7. /* 月份从0开始 */
    8. var month = date.getMonth()+1;
    9. console.log(month)
    10. var data = date.getDate();
    11. console.log(data)
    12. </script>

    获取当前的时间

    1. <script>
    2. var d = new Date();
    3. var hours = d.getHours();
    4. var minutes = d.getMinutes();
    5. var seconds = d.getSeconds();
    6. console.log(hours)
    7. console.log(minutes)
    8. console.log(seconds)
    9. </script>