一、數學對象:Math(不能被new)
重點:隨機數
求最大值(Math.max(1,2,3,4,5));
求最小值(Math.max(1,2,3,4,5));
求數組中最大值和最小值
(Math.min.apply(null.[數組]));
(Math.max.apply(null.[數組]));
Math.ceil();向上取整
Math.floor();向下取整
Math.rondom() 0-1之間的隨機數 (不包括0和1)
Math.floor(Math.random()*(max-min+1)+min)(兩個數之間的隨機數公式)
二、日期對象
//聲明一個日期對象,同時是獲取系統當前時間
var date=new Date(); cosole.log(date);
//自定義時間
var date=new Date(年/月/天/時:分:秒);
日期對象API:
年:FullYear
月:Month
天:Date
星期:Day(號)
時:Hours
分:Minutes
秒:Seconds
毫秒:Milliseconds
//獲取年
var year=now getFullyear();
console.log(year);
//獲取月
var moth=now.getMonth()+1;
console.log(moth);
//獲取日
var date=now.getDate();
console.log(date);
//獲取星期
var day=now.getDay();
console.log(day);
//獲取時
var hour=now.getHours();
console.log(hour);
//獲取分
var minu=now.getMinutes();
console.log(minu);
//獲取秒
var sec=now.getSeconds();
console.log(date);