js(基础知识梳理三)---Math、Date

214 阅读1分钟

Math

属性:

E 返回算术常量 e,即自然对数的底数(约等于2.718)。

LN2 返回 2 的自然对数(约等于0.693)。

LN10 返回 10 的自然对数(约等于2.302)。

LOG2E 返回以 2 为底的 e 的对数(约等于 1.414)。

LOG10E 返回以 10 为底的 e 的对数(约等于0.434)。

PI 返回圆周率(约等于3.14159)。

...

方法:

不涉及复杂计算的方法

Math.abs(x) 返回数的绝对值。

Math.ceil(x) 对数进行向上舍入

Math.floor(x) 对数进行向下舍入

Math.max(x,y) 返回 x 和 y 中的最大值。

Math.min(x,y) 返回 x 和 y 中的最小值

Math.pow(x,y) 返回 x 的 y 次幂

Math.random() 返回 0 ~ 1 之间的随机数。

Math.round(x) 把数四舍五入为最接近的整数。

......

Date

方法

date.getDate() 从 Date 对象返回一个月中的某一天 (1 ~ 31)。

date.getDat() 从 Date 对象返回一周中的某一天 (0 ~ 6)。

date.getMonth() 从 Date 对象返回月份 (0 ~ 11)。

date.getFullYear() 从 Date 对象以四位数字返回年份。

date.getHours() 返回 Date 对象的小时 (0 ~ 23)。

date.getMinutes() 返回 Date 对象的分钟 (0 ~ 59)。

date.getSeconds() 返回 Date 对象的秒数 (0 ~ 59)。

date.getMillisenconds() 返回 Date 对象的毫秒(0 ~ 999)。

date.getTime() 返回 1970 年 1 月 1 日至今的毫秒数。

.......