1、Math

  1. /*
  2. num<10000 正常显示
  3. num>10000 1+"万"
  4. num>100000000 "1亿"
  5. */
  6. var num = 100465000
  7. if(num<10000){
  8. console.log(num);
  9. }else if(num>=10000 && num<100000000){
  10. console.log(Math.ceil(num/10000)+"万");
  11. }else{
  12. console.log(num/100000000+"亿");
  13. }
  1. var arr = [
  2. {name:"你好",playCount:4000},
  3. {name:"它",playCount:400040},
  4. {name:"谁",playCount:200000000},
  5. ]
  6. arr.forEach(item=>{
  7. item.playCount = handleNum(item.playCount)
  8. })
  9. console.log(arr);

2、Date

  1. var date = new Date()
  2. var hours = date.getHours()
  3. var minutes = date.getMinutes()
  4. var seconds = date.getSeconds()
  5. var sum = dateTime(hours)+":"+dateTime(minutes)+":"+dateTime(seconds)
  6. function dateTime(num){
  7. if(num<10){
  8. num = "0"+num
  9. }
  10. }
  1. var date
  2. var hours
  3. var minutes
  4. var seconds
  5. setInterval(()=>{
  6. show()
  7. var template = `
  8. <p>${hours}:${minutes}:${seconds}</p>
  9. `
  10. $('body').append(template)
  11. }, 1000);
  12. function show(){
  13. date = new Date()
  14. hours = date.getHours()
  15. minutes = date.getMinutes()
  16. seconds = date.getSeconds()
  17. var sum = dateTime(hours)+":"+dateTime(minutes)+":"+dateTime(seconds)
  18. console.log(sum);
  19. }
  20. function dateTime(num){
  21. if(num<10){
  22. num = "0"+num
  23. }
  24. return num
  25. }
  1. var time = "2021-10-13 17:10:10"
  2. // 多少小时,多少分钟,多少秒
  3. var d = new Date()
  4. // 获取当前时间的毫秒数
  5. //console.log(d.getTime());
  6. var startTime = d.getTime()
  7. //console.log(Date.now());
  8. // 获取活动开始时间的毫秒
  9. var endTime = new Date(time).getTime()
  10. //console.log(endTime);
  11. // 得到中间间隔的毫秒数
  12. var gapTime = endTime - startTime
  13. console.log(gapTime);
  14. var seconds = Math.floor(gapTime/1000)
  15. console.log(seconds);
  16. var hours = Math.floor(seconds/3600)
  17. console.log(hours);
  18. seconds = seconds%3600
  19. console.log(seconds);
  20. var minutes = Math.floor(seconds/60)
  21. console.log(minutes);
  22. seconds = seconds - 60*minutes
  23. console.log(seconds);
  1. var time = "2021-10-19 08:30:00"
  2. var startTime = new Date().getTime()
  3. var endTime = new Date(time).getTime()
  4. var gapTime = endTime-startTime
  5. var minutes = Math.floor(gapTime/(1000*60))
  6. console.log(minutes);
  7. var days = Math.floor(minutes/(60*24))
  8. console.log(days+"天");
  9. minutes = minutes - days*(60*24)
  10. var hours = Math.floor(minutes/60)
  11. console.log(hours+"小时");
  12. minutes = minutes%60
  13. console.log(minutes+"分钟");
  1. function Time(time){
  2. var d = new Date()
  3. var startTime = d.getTime()
  4. var endTime = new Date(time).getTime()
  5. var gapTime = endTime - startTime
  6. console.log(gapTime);
  7. var seconds = Math.floor(gapTime/1000)
  8. console.log(seconds);
  9. var hours = Math.floor(seconds/3600)
  10. console.log(hours+"时");
  11. seconds = seconds%3600
  12. console.log(seconds);
  13. var minutes = Math.floor(seconds/60)
  14. console.log(minutes+"分");
  15. seconds = seconds%60
  16. console.log(seconds+"秒");
  17. }