Math对象和Date对象

Math对象:

用于执行数学任务的对象,使用其下的方法,可以执行相应的数学任务。

访问语法:Math.属性名

Math属性:E、LN2、LN10、LOG2E、LOG10E、PI、SQRT1_2、SQRT2

Math常用方法:

1、Math.abs(x)     作用:返回数的绝对值

2、Math.ceil(x)     作用:对数进行上取整

3、Math.floor(x)     作用:对数进行下取整

4、Math.max(x,y)    作用:返回 x 和 y 中的最高值

5、Math.min(x,y)    作用:返回 x 和 y 中的最低值

6、Math.round(x)   作用:把数四舍五入为最接近的整数

7、Math.pow(x,y)    作用:返回 x 的 y 次幂

8、Math.random()    作用:返回 0 ~ 1 之间的随机数

9、Math.sqrt(x)    作用:返回数的平方根


Date对象:

用于处理日期和时间。

创建 Date 对象的语法:var myDate=new Date()

获取时间方法:

Date()返回当日的日期和时间

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

getDay()从 Date 对象返回一周中的某一天 (0 ~ 6)

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

getFullYear()从 Date 对象以四位数字返回年份(如2018)

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

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

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

getMilliseconds()返回 Date 对象的毫秒(0 ~ 999)

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

getTimezoneOffset()返回本地时间与格林威治标准时间 (GMT) 的分钟差

getUTCDate()根据世界时从 Date 对象返回月中的一天 (1 ~ 31)

getUTCDay()根据世界时从 Date 对象返回周中的一天 (0 ~ 6)

getUTCMonth()根据世界时从 Date 对象返回月份 (0 ~ 11)

getUTCFullYear()根据世界时从 Date 对象返回四位数的年份

猜你喜欢

转载自blog.csdn.net/frost666/article/details/80751720
今日推荐