日期对象可以储存任意一个日期,并且可以精确到毫秒数(1/1000 秒)。
语法:var Udate=new Date();
注:初始值为当前时间(当前电脑系统时间)。
Math对象,提供对数据的数学计算。
注意:Math 对象是一个固有的对象,无需创建它,直接把 Math 作为对象使用就可以调用其所有属性和方法。这是它与Date,String对象的区别。
Math对象属性
Math对象方法
1):ceil()方法向上取整,返回的是大于或等于x,并且与x最接近的整数。
document.write(Math.ceil(0.8) + "<br />")//1 document.write(Math.ceil(6.3) + "<br />")//7 document.write(Math.ceil(5) + "<br />")//5 document.write(Math.ceil(3.5) + "<br />")//4 document.write(Math.ceil(-5.1) + "<br />")//-5 document.write(Math.ceil(-5.9))//-5
2):floor()方法向下取整,返回的是小于或等于x,并且与x最接近的整数。
document.write(Math.floor(0.8) + "<br />")//0 document.write(Math.floor(6.3) + "<br />")//6 document.write(Math.floor(5) + "<br />")//5 document.write(Math.floor(3.5) + "<br />")//3 document.write(Math.floor(-5.1) + "<br />")//-6 document.write(Math.floor(-5.9))//-6
3):round() 方法可把一个数字四舍五入为最接近的整数
document.write(Math.round(0.8) + "<br />")//1 document.write(Math.round(6.3) + "<br />")//6 document.write(Math.round(5) + "<br />")//5 document.write(Math.round(3.5) + "<br />")//4 document.write(Math.round(-5.1) + "<br />")//-5 document.write(Math.round(-5.9)+"<br />")//-6
4):random() 方法可返回介于 0 ~ 1(大于或等于 0 但小于 1 )之间的一个随机数。
document.write(Math.random());//返回0到1之间的数字 不包括1 document.write(Math.random()*10);//返回0到10之间的数字 不包括10
5):min()方法:返回一组数值中的最小值
document.write(Math.min(2,3,4,6));//2获取数组中最小值,使用apply()方法:
var values=[3,2,1,8,9,7]; document.write(Math.min.apply(Math,values)+"<br>");//1Math对象作为apply第一个参数,任意数组作为第二参数
6):max()方法:返回一组数值中的最大值
document.write(Math.max(2,3,4,6));//6获取数组中最小值,使用apply()方法:
var values=[3,2,1,8,9,7]; document.write(Math.max.apply(Math,values)+"<br>");//9
转载于:https://www.cnblogs.com/ToNi/p/4271825.html
相关资源:javascript 学习笔记(八)javascript对象