描述:当用打开页面的时候显示当前的日期。
实例代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>模拟日历</title>
</head>
<style>
    .time{
        width: 1200px;
        margin: 200px auto;
        color: red;
        text-align: center;
        font: 600 30px/30px "simsun";
    }
</style>
<body>
    <div class="time"></div>
</body>
</html>
<script>
    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth();
    var day = date.getDate();
    var week = date.getDay();
    var arr = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
    var time = document.getElementsByClassName("time")[0];
    time.innerText = "今天是"+year+"年"+(month+1)+"月"+day+"日,"+arr[week];
</script>
Last modification:April 9, 2018
If you think my article is useful to you, please feel free to appreciate