【JS】输出当前日期,精确至时间

Osinghong2个月前 (04-27)成果展示58
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>d24c04429</title>
</head>
<body>
    <script>
        var today = new Date();
        var dayOfWeek = ["日", "一", "二", "三", "四", "五", "六"][today.getDay()];
        var dayOfMonth = today.getDate();
        var month = today.getMonth() + 1;
        var year = today.getFullYear();
        var hours = today.getHours();
        var minutes = today.getMinutes();
        var seconds = today.getSeconds();
        hours = (hours < 10 ? "0" : "") + hours;
        minutes = (minutes < 10 ? "0" : "") + minutes;
        seconds = (seconds < 10 ? "0" : "") + seconds;
        console.log("今天是" + year + "年" + month + "月" + dayOfMonth + "日 星期" + dayOfWeek + " " + hours + ":" + minutes + ":" + seconds );
    </script>
</body>
</html>


打赏
分享给朋友:

相关文章