1、创建日期
注:其中月份是从0开始算起,所以要加上1
Paste_Image.png
2、date.getXXX()
Paste_Image.png
3、格式化
padding表示如果是个位数的在前面补个0,如04
4、date.setXXX()
Paste_Image.png
Paste_Image.png
注:超出时间时,浏览器自动转化
5、求天数
Paste_Image.png
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>获取某月的天数</title>
</head>
<body>
<script>
function getDays(year, month){
var date = new Date(year, month, 0);
return date.getDate();
}
alert('2001年2月有' + getDays(2001, 2) + '天。');
alert('2001年3月有' + getDays(2001, 3) + '天。');
</script>
</body>
</html>```
6、Date → Number

7.Number → Date
