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

2021-09-07 20:02:10 字數 560 閱讀 4987

math物件常用方法

math.pi 圓周率 π的值

math.random() 生成隨機數

例如:隨機生成5位數的隨機數

function f1()

return str;

}f1();

math.floor() 向下取整

math.ceil() 向上取整

math.round() 取整,四捨五入

math.abs() 絕對值

math.max() 最大值

math.min() 最小值

math.sin() 正弦

math.cos() 余弦

math.power() 求指數次冪

math.sqrt() 求平方根

date物件

getfullyear() 年

getmonth() 月

getdate() 日

getday() 星期

gethours () 時

getminutes() 分

getseconds () 秒

gettime() 毫秒數

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物件的方法

js中的物件 math物件 math.pi 圓周率 math.random 生成隨機數 math.floor 向下取整 math.ceil 向上取整 math.round 四捨五入取整 math.abs 絕對值 math.max 最大值 math.min 最小值 date物件 getfullyear...