1.Math
(1) Math.PI represents constant π
console.log(Math.PI) //3.1415926535
(2) Math.max () maximum
Math.min () minimum
console.log(Math.max(1,8,9,6,59,658,569,542)) //658 console.log(Math.min(658,569,542,586,358,785,459,264)) //264
(4) Math.ceil () ceiling, rounding up
Math.floor () rounding down floor
console.log(Math.ceil(3.1)) //4 console.log(Math.floor(3.7)) //3
(6) Math.round () rounding
console.log(Math.round(3.1)) //3 console.log(Math.round(3.7)) //4
(7) Math.random random number [0 to 1)
[0~1) :
console.log(Math.random()) //0.8593806925764069
[0~3) :
console.log(Math.random()) //2.7221629645726204
An integer between [0-3]
console.log(Math.floor(Math.random()*4))
(8) Math.abs absolute value
console.log(Math.abs(-3.1)) //3.1 console.log(Math.abs(3.7)) //3.7
2.Data date and time
(1) new Date () to create the current time
var date=new Date() console.log(date)
(2) Time Format
var date=new Date() console.log(date.toLocaleString()) //2019/9/29 下午8:35:13
var date=new Date() console.log(date.toLocaleDateString()) //2019/9/29
var date=new Date() console.log(date.toLocaleTimeString())
(3) for specific dates
var date=new Date() console.log(date.getFullYear()) //2019
var date=new Date()
console.log(date.getMonth()+1) //
var DATE = new new a Date () the console.log (date.getDay ()) // 0 Sunday
var date=new Date() console.log(date.getHours()) //20
var date=new Date() console.log(date.getMinutes()) //48
var date=new Date() console.log(date.getSeconds())
(4) the timestamp from 1970 to the present time in milliseconds total
var date=+new Date() console.log(date)
(5) Countdown
Time difference: T = parseInt ((end timestamp -start timestamp) / 1000)
Day: day = parseInt (T / 3600/24)
H: hour = parseInt (T / 60/60)% 24
分 : minute=parseInt(T/60)%60
Sec: second = time% 60