JSAPI2.2—日期
一、实例化
示例:const date = new Date()
二、日期对象方法
方法 | 作用 | 说明 |
---|---|---|
getFullYear() | 获得年份 | 获取四位年份 |
getMonth() | 获得月份 | 取值为0-11 |
getDate() | 获取月份中的每一天 | 不同月份取值也不相同 |
getDay() | 获取星期 | 取值0-6(利用数组) |
getHours() | 获取小时 | 取值0-23 |
getMinutes() | 获取分钟 | 取值0-59 |
getSecords() | 获取秒 | 取值0-59 |
三、时间戳
3.1什么是时间戳:是指1970年01月01日00时00分00秒起到现在的毫秒数,是一种特殊的计量 事件方式
3.2算法:将来的时间戳-现在的时间戳=剩余时间毫秒数
3.3获得时间戳的方式:
//1.getTime()
const date = new Date()
console.log(date.getTime());
//2.+new Date(),无需实例化
console.log(+new Date());
//3.Date.now(),无需实例化,但只能得到当前的时间戳,前两种可以返回指定时间的时间戳
console.log(Date.now());