javascript——Math、Date

来源:互联网 发布:淘宝培训班多少钱 编辑:程序博客网 时间:2024/06/15 09:57

Math:

1、Math.floor:向下取整

2、Math.ceil:向上取整

3、Math.round:四舍五入,若为负数,+0.5用floor。

4、Math.abs:转化为绝对值

5、Math.max:最大值,只用于数字。

6、Math.pow(底数,指数):2的2次方

7、Math.sqrt(底数,指数):根号3

8、Math.random():返回0-1 ,0可取到,1不可。:Math.floor(Math.random()*10):0-10


Date:

定义:var time = new Date();

1、 .getTime() :返回1970年1月1日对应的毫秒数

2、.getDate():对应几号

3、.getDay():返回星期几

4、.getYear():距1900的年数

5、.getFullYear() :当前时间的四位数的年份

6、.getMonth():当前时间的月份:0位1月,11位12月

7、.getHours():小时 0-23

8、.getMinutes():分钟

9、.getSeconds():秒

10、.getMilliseconds():毫秒

11、end-now:返回两个时间点相减的毫秒数

12、end+now:返回联合各字符串拼接起来的

13、Number(end)+Number(now):返回两个时间点相加的毫秒数

14、parseInt():小数点不要

0 0
原创粉丝点击