Math对象
- 一些静态方法
- Math.abs()取绝对值
- Math.ceil()向上取整
- Math.floor()向下取整
- Math.max()最大值
- Math.min()最小值
- Math.round()四舍五入
- Math.random()随机数
- Math.pow()幂运算
- Math.log()自然对数
- 三角函数方法
Date对象
- 普通函数的用法
参数无效 Date(2000, 1, 1) // "Tue Dec 01 2015 09:34:43 GMT+0800 (CST)"
- 构造函数的用法
Date实例求值的时候,默认调用的是toString()方法,返回的是一个字符串,代表该实例对应的时间var today = new Date(); today // "Tue Dec 01 2015 09:34:43 GMT+0800 (CST)"
- 实例方法
- valueOf()
返回实例对象距离时间零点(1970年1月1日00:00:00 UTC)对应的毫秒数,该方法等同于getTime方法var d = new Date(); d.valueOf() // 1362790014817 d.getTime() // 1362790014817
- to类方法
- toString()
- toISOString()
var d = new Date(2013, 0, 1); d.toISOString() // "2012-12-31T16:00:00.000Z"
- toDateString()
- toTimeString()
- get类方法 用来获取实例对象某个方面的值
- getDate()日
- getTime()距离1970年1月1日00:00:00的毫秒数
- getDay()星期
- getMonth()月
- getFullYear()年
- getHours()小时
- getMinutes()分钟
- getSeconds()秒
let x = new Date() console.log(x.getDate()) // 17 console.log(x.getDay()) // 1 console.log(x.getMonth()) // 7 console.log(x.getFullYear()) // 2020 console.log(x.getTime()) // 1597653545261 console.log(x.getHours()) // 16 console.log(x.getMinutes()) // 41 console.log(x.getSeconds()) // 5
- valueOf()