<!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>
01-js_Date()构造.html
于 2019-04-03 10:02:11 首次发布