Math
四舍五入
Math.round()
向上取整
Math.ceil()
向下取整
Math.floor()
取最大值
Math.max()
取最小值
Math.min()
取x的y次幂
Math.pow(x,y)
求x的平方根
Math.sqrt(x)
绝对值
Math.abs()
指定范围随机数,例[m,n]
var randNum = Math.floor(Math.random()*(n-m+1))+m;
例[65,97]
var randNum = Math.floor(Math.randrom()*33)+65;
Date
获取当前日期
var oDate = new Date();
console.log(oDate);
指定日期
var oDate = new Date("2019-08-21 20:24:00");
console.log(oDate);
返回一个月的某一天(1~31)
oDate.getDate();
返回一周的某一天 (0~6)
oDate.getDay();
返回月份(0~11)
oDate.getMonth();
以四位数字返回年份
oDate.getFullYear();
返回小时
oDate.getHours();
返回分钟
oDate.getMinutes();
返回秒
oDate.getSeconds();
设置10天以后的日期
oDate.setDate(oDate.getDate()+10);
定时器
setInterval(fn,time); //每隔time时间,执行fn
倒计时
var count=5;
box.innerText = count; //防止出现1秒空白
var timer = setInterval(function(){
count--;
box.innerText = count;
if(count==0){
box.innerText = "倒计时结束";
clearInterval(timer); //定时器结束
}
},1000);