Create a Time object
var time=new Date(); //当前时间,()内可写入字符串 ,如‘2017-10-10‘,可转为响应的时间
Common methods
time.getFullYear(); //从 Date 对象以四位数字返回年份。time.getMonth(); //从 Date 对象返回月份 (0 ~ 11)。time.getDate(); //从 Date 对象返回一个月中的某一天 (1 ~ 31)。time.getDay(); //从 Date 对象返回一周中的某一天 (0 ~ 6)。周日为0;time.getHours(); //返回 Date 对象的小时 (0 ~ 23)。time.getMinutes(); //返回 Date 对象的分钟 (0 ~ 59)。time.getSeconds(); //返回 Date 对象的秒数 (0 ~ 59)。time.getMilliseconds(); //返回 Date 对象的毫秒(0 ~ 999)。time.getTime(); //返回 1970 年 1 月 1 日至今的毫秒数。time.getTimezoneOffset(); //返回本地时间与格林威治标准时间 (GMT) 的分钟差。
Mathematical objects
Math.abs(x); //返回数的绝对值。Math.ceil(x); //进一取整Math.floor(x); //退一取整Math.min(x,y); //取最小值Math.max(x,y); //取最大值Math.round(x); //四舍五入Math.random(); //0-1见的随机数,有0无1Math.pow(x,y); //x的y次幂
Find a random number of Min-max (and include Min and Max):
function random(min,max){ return Math.round(Math.random()*(max-min)+min);}
JavaScript--Common date objects and math objects