Date
date :是日期对象,是一个构造函数
使用Date时如果括号没有参数,返回的时当前系统时间
Date获取当前系统时间:
getFullYear() 获取当前
getMonth() 获取当月
getDate() 获取当天日期
getDay() 获取星期几 (周日为0周一为1.......6)
getHours() 获取当前小时(0~23)
getMinutes() 获取当前分钟(0~59)
getSeconds() 获取当前秒(0~59);
getMilliseconds() 获取当前毫秒
时间戳就是一串数字,获取时间戳
Date.new() 当前日期的时间戳
+日期对象 日期对象转时间戳
日期对象.getTime() 日期对象转时间戳
Date.parse(日期对象) 日期对象、日期字符串转时间戳
将Date 对象的日期部分转换为字符串
toLocaleString() 获取当前年月日时分秒格式
可以将时间转24小时制例:console.log(new Date().toLocaleString('chinese',{hour12:true}));
toLocaleDateString() 获取当前年月日
toLocaleTimeString() 获取当前时分秒
日期的比较
日期的比较可以用> >= 或 < <=做比较,但不可以用==和===作比较
比较是否相等可以用:转时间戳比较
创建日期
new Date() //获取当前时间
new Date('日期字符串') //字符串获取年月日
new Date(时间戳) //时间戳转日期对象
new Date(年,月,日,时,分) //获取指定年月日时分。月份从0开始
设置Date时间;其实也就是get切换set而已
当set超出范围时会做加法进位,当是负数时做减法
日期对象名.setFullYear() 可设置年月日
日期对象名.setMonth() 设置月日(0~11)(0~23)
日期对象名.setDate() 设置日(1~31)
日期对象名.setHours() 设置时分秒(0~23)
日期对象名.setMinutes 设置分秒(0~59)
日期对象名.setSeconds 设置秒(0~999)