1、播放量

  1. <script>
  2. var num = 101000000;
  3. if(num>100000000){
  4. num = num/100000000 + "亿"
  5. }else if(num>=10000){
  6. num = Math.ceil(num/10000)+"万"
  7. }
  8. console.log(num);
  9. </script>
  1. <script>
  2. function handleNum(num){
  3. if (num > 100000000) {
  4. num = num / 100000000 + "亿"
  5. } else if (num >= 10000) {
  6. num = Math.ceil(num / 10000) + "万"
  7. }
  8. return num;
  9. }
  10. var res = handleNum(100000);
  11. console.log(res);
  12. </script>
  1. <script>
  2. function handleNum(num){
  3. if(num>=100000000){
  4. num = num/100000000+"亿"
  5. }else if(num>=10000){
  6. num = num/10000+"万"
  7. }
  8. return num+"";
  9. }
  10. var arr = [
  11. {name:"你好",playcount:4000},
  12. {name:"它",playcount:400040},
  13. {name:"谁",playcount:20000000000}
  14. ]
  15. arr.forEach(item=>{
  16. item.playcount = handleNum(item.playcount);
  17. })
  18. console.log(arr)
  19. </script>

1.1、{name: ‘你好’, playCount: ‘4000’}

  1. <script>
  2. function handleNum(num){
  3. if(num>=100000000){
  4. num = num/100000000+"亿"
  5. }else if(num>=10000){
  6. num = num/10000+"万"
  7. }
  8. return num+"";
  9. }
  10. var arr = [
  11. /* 4000 */
  12. {name:"你好",playCount:4000},
  13. /* 40万 */
  14. {name:"它",playCount:400040},
  15. /* 2亿 */
  16. {name:"谁",playCount:200000000}
  17. ]
  18. arr.forEach(item=>{
  19. item.playCount = handleNum(item.playCount);
  20. })
  21. console.log(arr)
  22. </script>

2、输入时间

  1. <div id="app"></div>
  2. <script>
  3. setInterval(show,1000)
  4. function show(){
  5. var app = document.getElementById("app");
  6. var d = new Date();
  7. var hours = d.getHours();
  8. var minutes = d.getMinutes();
  9. var seconds = d.getSeconds();
  10. var sum = handleNum(hours) + ":" + handleNum(minutes) + ":" + handleNum(seconds);
  11. console.log(sum);
  12. app.innerHTML = sum;
  13. }
  14. function handleNum(num) {
  15. if (num < 10) {
  16. num = "0" + num;
  17. }
  18. return num;
  19. }
  20. </script>

3、现在时间

  1. <script>
  2. var d = new Date();
  3. var hours = d.getHours();
  4. var minutes = d.getMinutes();
  5. var seconds = d.getSeconds();
  6. var sum = handleNum(hours)+":"+handleNum(minutes)+":"+handleNum(seconds);
  7. console.log(sum)
  8. function handleNum(num){
  9. if(num<10){
  10. num = "0"+num;
  11. }
  12. return num;
  13. }
  14. </script>

4、距离2021-10-13 17:10:10还剩多少时间

  1. <script>
  2. var time = "2021-10-13 17:10:10"
  3. /* 多个小时,多分钟,多少秒 */;
  4. /* 1、获取当前时间的毫秒数 */
  5. var d = new Date();
  6. // console.log(d.getTime())
  7. var startTime = d.getTime();
  8. /* 2、获取活动开始时间的毫秒 */
  9. var endTime = new Date(time).getTime();
  10. // console.log(endTime)
  11. /* 3、得到中间间隔的毫秒数 */
  12. var gapTime = endTime -startTime;
  13. var seconds = Math.floor(gapTime/1000)
  14. console.log(seconds)
  15. var hours = Math.floor(seconds/3600);
  16. console.log(hours)
  17. seconds = seconds - 3600*hours;
  18. var minutes = Math.floor(seconds/60);
  19. console.log(minutes)
  20. seconds = seconds - minutes*60;
  21. console.log(seconds)
  22. /* var time = "2021-10-13 21:30:00" 第一个需求*/
  23. /* var time ="2021-10-19 08:30:00" 还有几天几小时几分 */
  24. </script>

5、分秒时间的换算

  1. <script>
  2. var time = 360000;
  3. /*
  4. 66s
  5. */
  6. /*
  7. 一秒
  8. 60s 一分钟
  9. 60*60 一小时
  10. time/1000 秒
  11. */
  12. var seconds = Math.floor(time/1000);
  13. console.log(seconds)
  14. var hours = Math.floor(seconds/3600);
  15. console.log(hours)
  16. // seconds = seconds- hours*3600;
  17. seconds = seconds%3600;
  18. console.log(seconds)
  19. var minutes = Math.floor(seconds/60);
  20. console.log(minutes)
  21. seconds = seconds- minutes*60;
  22. console.log(seconds)
  23. </script>
  1. <script>
  2. var time = 306000;
  3. /* 3000
  4. 1m = 60s
  5. */
  6. var seconds = time/1000;
  7. console.log(seconds+"秒")
  8. var minutes = Math.floor(seconds/60);
  9. var seconds = seconds - minutes*60;
  10. console.log(minutes+"分")
  11. console.log(seconds+"余下的秒")
  12. /* 3s */
  13. </script>
  1. <script>
  2. var time = 306150000;
  3. /* 3000
  4. 1m = 60s
  5. 1h = 60*60s
  6. */
  7. var seconds = time/1000;
  8. console.log(seconds+"秒")
  9. var hours = Math.floor(seconds/3600);
  10. console.log(hours)
  11. var 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. /* 3s */
  18. </script>

6、2021-10-19 08:30:00” 还有几天几小时几分

  1. <script>
  2. /* var time ="2021-10-19 08:30:00" 还有几天几小时几分 */
  3. var time = "2021-10-19 08:30:00"
  4. var startTime = (new Date()).getTime();
  5. var endTime = (new Date(time)).getTime();
  6. var gapTime = endTime-startTime;
  7. var minutes = Math.floor(gapTime/(1000*60));
  8. /*
  9. 8201分
  10. 1h = 60m
  11. 1t = 60*24
  12. */
  13. // console.log(minutes)
  14. var days = Math.floor(minutes/(60*24));
  15. minutes = minutes -days*(60*24)
  16. console.log(days)
  17. var hours = Math.floor(minutes/60);
  18. console.log(hours)
  19. minutes = minutes - hours*60;
  20. console.log(minutes)
  21. </script>