对象分 内置对象(Math、Date、Array、String 等)、宿主对象(BOM、DOM 对象)、用户自定义对象。
Math
- Math.abs()绝对值
- Math.floor()向下取整 2.4 => 2 (地板函数) -2.4 => -3 取小的
- Math.ceil()向上取整 2.4 => 3 (天花板函数) -2.4 => -2 取大的
- Math.round()四舍五入 2.4 => 2 2.6 => 3 -2.4 => -2 -2.6 => -3 -2.5 => -2 正数四舍五入,负数五舍六入- 由于表示浮点数时存在精度问题,所以 2.4999999999999999 (相当于 2.5)=> 3 
- Math.max()
- Math.min()
- Math.pow(2, 7)2 的 7 次方
- Math.sqrt()开平方,只取正数根
- Math.random()取值 [0,1) 一般与向下取整使用- Math.floor(Math.random() * 10 + 5)取值 [5, 10)
Date
| 1 | // 需要实例化后使用 | 
- date.getFullYear()获取年份
- date.getMonth()获取月份 [0,11]
- date.getDate()获取日
- date.getDay()获取周几
- date.getHours()获取小时
- date.getMinutes()获取分钟
- date.getSeconds()获取秒
- date.getMilliseconds()获取毫秒
- date.getTime()获取时间戳(从 1970 年 1 月 1 日整点到现在的毫秒数,即 Unix 时间元年为起点)可以用来计算执行代码的时间。和时间相关的功能基本都是使用了这个。
- // 这是已经定义好的格式,不用自己拼接字符串了 var now = new Date() // 星期几 月 日 年 console.log(now.toDateString()) // 时 分 秒 时区 console.log(now.toTimeString()) // 2020/4/18 console.log(now.toLocaleDateString()) // 上午11:05:45 console.log(now.toLocaleTimeString()) // 2020/4/18 上午11:06:56 console.log(now.toLocaleString()) // 国际:Sat, 18 Apr 2020 03:08:43 GMT console.log(now.toUTCString())
以上都是针对已经实例化的对象的时间来获取的,它是不会变的,如果想要变化,重新建一个 Date 对象。
 
    


