js new Date().html

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>new Date()</title>
</head>
<body>
    <script>
        // 4.new Date(year, month, day?, hours?, minutes?, seconds?, milliseconds?)
        // 上面的参数大多数都是可选的,在不指定的情况下,默认参数是0。
        var d3 = new Date(79,5,24,11,33,0);
        console.log(d3);
        // Sun Jun 24 1979 11:33:00 GMT+0800 (中国标准时间)


        // 3.new Date(dateString)
        var d1 = new Date("October 13, 1975 11:13:00");
        console.log(d1);
        // Mon Oct 13 1975 11:13:00 GMT+0800 (中国标准时间)

        var d2 = new Date('Mon Oct 13 1975 11:13:00');
        console.log(d2);
        // Mon Oct 13 1975 11:13:00 GMT+0800 (中国标准时间)

        var d2 = new Date('Oct 13 1975 11:13:00');
        console.log(d2);
        // Mon Oct 13 1975 11:13:00 GMT+0800 (中国标准时间)

        var myDate = new Date("2017/12/25 17:00:00");
        console.log(myDate);
        // Mon Dec 25 2017 17:00:00 GMT+0800 (中国标准时间)


        // 2.new Date(milliseconds)
        d1 = new Date(152422609553);
        console.log(d1);
        // Thu Oct 31 1974 11:36:49 GMT+0800 (中国标准时间)


        // 1.new Date() // 当前日期和时间
        d1 = new Date();
        console.log(d1);
        // Mon Oct 08 2018 17:33:03 GMT+0800 (中国标准时间)
    </script>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/weixin_42193179/article/details/88988787