JS中的date物件和math物件的用法

2021-09-10 12:11:49 字數 1131 閱讀 1889

日期物件,是用來獲取時間和設定時間。

(1)獲取時間,獲取時間是從2023年0點開始

var time=new date();

(2)獲取

time.getfullyear()     獲取的是當前的年份

time.getyear()       返回的是從2023年開始到現在的總數

輸出的結果是119.

time.getmonth()     獲取到的是月份,因為返回的是索引值並且是從0開始的,所以要返回的時候給後邊加1;

time.getday()    獲取到週幾

time.getdate()   返回的是當前月中的幾號

time.gethour()    返回當前的小時

time.getminutes()      返回當前分鐘

time.getseconds()     返回當前的秒

time.getmillseconds()    返回毫秒

time.todatestring()     返回的是當前的年月日乃至週幾     (fri feb 1 2019)

time.tolocaledatestring()   返回年月日(2019/2/1)

time.tolocalestring()      返回年月日以及時間

time.tolocaletimestring()     僅僅返回時間 

math 物件中有自己的封裝方法,math物件為計算提供了簡便的途徑。接下來showtime  

math.abs();    取絕對值

math.ceil();   向上取整

math.floor()   向下取整  

math.round()   四捨五入
math.random()    隨機數  其中隨機數的取值是在0-1之間  

math.pow()     次冪 

3 的3次冪  輸出的結果是27  

完成!啦啦啦

js中Math和Date物件

1.math 普通函式,就是乙個物件 比較math.min math.max math.ceil 向上取整 math.floor 向下取整 math.round math.random 隨機數,0 1之間.不包括1,沒有引數 math.log 對數 math.sin 正弦函式 math.cos 余弦...

js中Math物件和Date物件

math 是數學函式,但又屬於物件資料型別 typeof math object 它是乙個物件 console.dir math 檢視math的所有函式方法。控制台列印的結果如下 1,math.abs 獲取絕對值 math.abs 12 12 2,math.ceil and math.floor 向...

js的Date和Math的物件

date和math date物件 定義 var d new date vard newdate 2017,4 22,19 05,22 不給引數,定義的日期為執行這條指令時那一刻的系統日期 當然也可以指定年月日時分秒引數,但是要特別注意的是月從0開始,即0表示1月 修改日期分量 setyear set...