1、math

  1. <script>
  2. var sum = 13.45
  3. console.log(Math.ceil(sum))
  4. console.log(Math.floor(sum))
  5. console.log(Math.round(13.16)) //四舍五入取整
  6. console.log(Math.max(4,5,6)) //取最大值
  7. console.log(Math.min(4,5,6)) //取最小值
  8. </script>
  9. Math.max() 取最大值
  10. Math.min() 取最小值
  11. Math.ceil() 向上取整
  12. Math.floor() 向下取整
  13. Math.round() 四舍五入
  14. Math.random() 随机数
  1. <script>
  2. var arr = [4,5,6];
  3. // var max = arr[0];
  4. // for(var i = 1;i<arr.length;i++){
  5. // if(arr[i]>max){
  6. // max = arr[i];
  7. // }
  8. // }
  9. console.log(Math.max(...arr));
  10. console.log(Math.min(...arr))
  11. </script>

2、date

  1. var d = new Date()
  2. /* 年,月,日 */
  3. var year = d.getFullYear()
  4. var month = d.getMonth()+1 // 月份是从0开始的,要加1
  5. var date = d.getDate()
  6. /* 时,分,秒 */
  7. var hour = d.getHours();
  8. var minute = d.getMinutes();
  9. var second = d.getSeconds();
  10. var mills = d.getTime(); //毫秒 1s = 1000毫秒
  11. console.log(d);
  12. console.log(year);
  13. console.log(month);
  14. console.log(date);
  15. console.log(hour);
  16. console.log(minute);
  17. console.log(second);
  1. <script>
  2. var date = new Date();
  3. console.log(date)
  4. var year = date.getFullYear();
  5. console.log(year)
  6. var month = date.getMonth()+1;
  7. console.log(month)
  8. var data = date.getDate();
  9. console.log(data);
  10. </script>