js內建物件(date物件和math物件)

2022-07-07 09:54:12 字數 1612 閱讀 5398

一、date物件

date物件用於處理日期和時間

date物件

使用date物件獲取時分秒

1、語法:

var 日期物件

= new date

(引數)

;date

物件date物件裡面的引數  大多數都是可選的  在不指定的情況下, 預設是

02、常用的函式

二、math物件

math物件用於執行數學任務

math物件是乙個物件但不是乙個函式

math物件屬性和方法

1、math物件常用的屬性和方法

math.floor():向下取整(下捨去) 

math.ceil():向上取整(上進入) 

math.round():四捨五入 

math.abs():取絕對值 

math.max():比較(取大) 

math.min():比較(取小) 

math.pow() : 取冪(兩個引數第乙個引數為底數,第二個為指數) 

math.sqrt() : 開平方 

math.random:0~1的乙個隨機數

math.cos():余弦值 

math.sin():正弦值 

對常用隨機數方法的擴充套件: 

1、math.round(math.random())//0,1隨機 

2、math.round(math.random()*a) //0~a隨機 

3、math.round(math.random()*(a-b)+b)//b~a隨機

三、封裝物件

1、封裝乙個物件,用來求多個數字的最大值,最小值

function mymath() 

}return max;

}this.getmin=function(arr)

}return min;

}this.geta=function(arr)

}console.log("awef"+arr[min]);

return min;}}

var a=new mymath();

console.log( "最大值為"+ a.getmax(56,23,3,234,234,32,34,32,4,23,423,4,23,6));

console.log("最小值為"+ a.getmin(56,23,3,234,234,32,34,32,4,23,423,4,23,6));

var arr=[2,234,234,54,28,3,724,234,23,4]

console.log("最小值為"+ a.geta(arr));

結果為:

其中 ...res(res可以是任意合法的名稱)和arguments用法類似      ...res是es6中的新語法,而arguments是es5中的語法

js內建物件 Date物件

date物件 data物件可以儲存任意乙個日期,並且可以精確到毫秒數 1 1000 秒 定義 預設初始值定義 var dataname new date 使用關鍵字new data首字母必須大寫 使dataname成為物件,同時具有初始值 當前電腦系統時間 自定義初始值定義 var dataname...

Js內建物件 Date

var now new date console.log now fri oct 19 2018 17 53 57 gmt 0800 中國標準時間 初始化自定義日期時間物件 var aaaa new date 2018 05 01 console.log aaaa tue may 01 2018 0...

js內建的Date物件

created by mengbao on 2018 12 14.建立date物件 方法1 不指定引數 var d1 new date console.log d1 console.log typeof d1 console.log d1.tolocalestring console.log typ...