Math物件和Date物件的方法

2021-09-07 19:54:48 字數 456 閱讀 9032

js中的物件

math物件

math.pi 圓周率

math.random() 生成隨機數

math.floor() 向下取整

math.ceil() 向上取整

math.round() 四捨五入取整

math.abs() 絕對值

math.max() 最大值

math.min() 最小值

date物件

getfullyear() 獲取年份

getmonth() 獲取月份

gethours() 獲取小時

getminutes 獲取分鐘

getseconds() 獲取秒鐘

getdate() 返回當月的第幾天

getday() 返回乙個星期的第幾天

tostring() // 轉換成字串

valueof() // 獲取毫秒值

Date物件和Math物件

var time new date 獲取的是當前時間 var time new date 2000 1970年1月1日 8時0分2秒 20000是毫秒數 var time new date 98,10,20,0,0,0 1998年10月10日 0時0分0秒分3大組 get 用於獲取時間和日期值 se...

Math物件和Date物件

字串 初始化方式 字面量 建構函式 儲存方式 ascii unicode utf 8就是八位的unicode編碼 屬性length屬性 表示字串的長度 length屬性唯讀 可以通過下標的方式獲取對應位置的字元 迴圈可以使用for迴圈 也可以使用for in 迴圈 方法charat 用來獲取對應位置...

Math 物件和Date物件的常用屬性和方法

math物件常用方法 math.pi 圓周率 的值 math.random 生成隨機數 例如 隨機生成5位數的隨機數 function f1 return str f1 math.floor 向下取整 math.ceil 向上取整 math.round 取整,四捨五入 math.abs 絕對值 ma...