<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>设置时间</title>
</head>
<body>
<script>
// 2022/5/23 9:10:30
// 2022-05-23 09:10:03
//
var now = new Date();
console.log('now---', now);
var setTime1 = new Date('2022/5/23, 9:10:30');
console.log('setTime1---', setTime1);
var setTime2 = new Date('2022/5/23 9:10:30');
console.log('setTime2---', setTime2);
var setTime3 = new Date(2022,05,23,09,10,30); // 注意月份
console.log('setTime3---', setTime3);
var setTime4 = new Date('May 23, 2022, 09:20:11');
console.log('setTime4---', setTime4);
//无范围
now.setFullYear(2222);
console.log('新 年份 ---', now.getFullYear());
//范围是0-11
now.setMonth(13); // 显示1, 实际2月
console.log('新 月份 ---', now.getMonth()); // 0-11
//范围是0-28 因为是平年2月
now.setDate(31);
console.log('新 天数 ---', now.getDate());
//范围是0-24
now.setHours(25);
console.log('新 小时 ---', now.getHours());
//范围是0-60
now.setMinutes(61);
console.log('新 分钟 ---', now.getMinutes());
//范围是0-60
now.setSeconds(62);
console.log('新 秒级 ---', now.getSeconds());
//范围是0-999
now.setMilliseconds(1000);
console.log('新 毫秒 ---', now.getMilliseconds());
</script>
</body>
</html>
上述运行结果: