var d = new Date();console.log(d);創建一個指定時間的對象,需要在構造函數中傳遞一個表示時間的字符串作為參數var d2 = new Date("12/23/2020 20:30:00");console.log(d2);console.log(d2.getDate();)console.log(d2.getDay());console.log(d2.getMonth()); 4、獲取當前日期對象年份:getFullYear()console.log(d2.getFullYear());console.log(d2.getHours()); 6、獲取當前日期對象分鐘:getMinutes()console.log(d2.getMinutes());console.log(d2.getSeconds()); 時間戳指的是格林威治標準時間的1970年1月1日,0時0分0秒 到當前日期所花費的毫秒數(1秒 = 1000毫秒)console.log(d2.getTime());var start = Date.now()for(var i=0;i<100;i++){ console.log(i);}var end = Date.now();console.log("執行了:"+(end-start)+"毫秒");和其他的對象不同,它不是一個構造函數,它屬於一個工具類不用創建對象,它裡面封裝了數學運算相關的屬性和方法,比如Math.PI 表示圓周率1、Math.abs()可以用來計算一個數的絕對值console.log(Math.abs(-2)); 2、Math.ceil() 可以對一個數進行向上取整,小數位只要有值就自動進1console.log(Math.ceil(1.1)); 3、Math.floor() 可以對一個數進行向下取整,小數部分會被舍掉console.log(Math.floor(2.6)); 4、Math.round() 可以對一個數進行四捨五入console.log(Math.round(1.4)); console.log(Math.round(1.5)); 5、Math.random() 可以用來生成一個0-1之間的隨機數console.log(Math.random());console.log(Math.random()*10);console.log(Math.random()*x);Math.round(Math.random()*(y-x))+x9、Math.min(a,b,c) 可以獲取多個數中的最小值console.log(Math.min(2,8,3,10));10、Math.max(a,b,c) 可以獲取多個數中的最大值console.log(Math.max(2,8,3,7));console.log(Math.pow(2,3));
Long-press QR code to transfer me a reward
As required by Apple's new policy, the Reward feature has been disabled on Weixin for iOS. You can still reward an Official Account by transferring money via QR code.