01-js_Date()构造.html

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>js Date()构造</title>
</head>
<body>

<script>
    /*参考:https://www.runoob.com/js/js-obj-date.html*/
    // 1.Date()
    // Date 对象会自动把当前日期和时间保存为其初始值。
    // 以下3行代码的效果相同。
    console.log("\n1:");
    console.log(Date());
    console.log(new Date());
    console.log(new Date);
    // Mon Apr 06 2020 12:15:25 GMT+0800 (中国标准时间)

    // 2.new Date(milliseconds)
    console.log("\n2:");
    let d2 = new Date(162422609553);
    console.log("d2:", d2);
    // d2: Mon Feb 24 1975 05:23:29 GMT+0800 (中国标准时间)
    let d = new Date(-2209161600000);
    console.log("d:", d);
    // d: Sat Dec 30 1899 08:05:43 GMT+0805 (中国标准时间)
    console.log(d.toLocaleDateString());
    // 1899/12/30

    // 3.new Date(dateString)
    console.log("\n3:");
    let ds1 = new Date("October 13, 1975 11:13:00");
    console.log("ds1:", ds1);
    // ds1: Mon Oct 13 1975 11:13:00 GMT+0800 (中国标准时间)
    let ds2 = new Date('Mon Oct 13 1975 11:13:00');
    console.log("ds2:", ds2);
    // ds2: Mon Oct 13 1975 11:13:00 GMT+0800 (中国标准时间)
    let ds3 = new Date('Oct 13 1975 11:13:00');
    console.log("ds3:", ds3);
    // ds3: Mon Oct 13 1975 11:13:00 GMT+0800 (中国标准时间)
    let ds4 = new Date("2017/12/25 17:00:00");
    console.log("ds4:", ds4);
    // ds4: Mon Dec 25 2017 17:00:00 GMT+0800 (中国标准时间)
    let ds5 = new Date("2020-03-31 09:05:02");
    console.log("ds5:", ds5);
    // ds5: Tue Mar 31 2020 09:05:02 GMT+0800 (中国标准时间)

    // 4.new Date(year, month, day?, hours?, minutes?, seconds?, milliseconds?)
    // 上面的参数大多数都是可选的,在不指定的情况下,默认参数是0。
    // month,用0-11表示,1-12月份。其中0,表示1月;11,表示12月。
    console.log("\n4:");
    let d4 = new Date(2019, 7, 5, 16, 27, 0, 0);
    console.log("d4:", d4);
    // d4: Mon Aug 05 2019 16:27:00 GMT+0800 (中国标准时间)
</script>

</body>
</html>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值