关于的日期获取和设置
获取以 get开头 设置以 set开头
var currentDate = new Date() //获取当前的时间
获取年
console.log(currentDate.getFullYear()); //获取当前本地时间的年份
获取月
console.log(currentDate.getMonth()); //获取当前的月份 0 - 11 1月就是0 12月是11
获取日
console.log(currentDate.getDate()); //当月的第几日
console.log(currentDate.getDay()); //星期的第几日 星期天是第一天(从0开始算)
获取时
console.log(currentDate.getHours());//获取小时 24小时制 12点就是12 24点就是0
获取分
console.log(currentDate.getMinutes()); //获取分钟
获取秒
console.log(currentDate.getSeconds()); //获取秒钟
加了utc就是获取utc时间 没有加就是获取本地时间
一般称为时间戳 这个一般作为唯一标识(有些时候数据过大我们还会在后面加随机数)
console.log(currentDate.getTime()); //获取距离1970年1月1日0时0分0秒的毫秒值
设置方法 Date是可变的
currentDate.setFullYear(2020) //设置年
currentDate.setDate(30) //设置当月的第几天
currentDate.setHours(10)
currentDate.setMinutes(10)
currentDate.setSeconds(10)
console.log(currentDate);
currentDate.setTime(123456789) ; //设置离1970年1月1日0时0分0秒的毫秒值
console.log(currentDate);