1、Math
/*
num<10000 正常显示
num>10000 1+"万"
num>100000000 "1亿"
*/
var num = 100465000
if(num<10000){
console.log(num);
}else if(num>=10000 && num<100000000){
console.log(Math.ceil(num/10000)+"万");
}else{
console.log(num/100000000+"亿");
}
var arr = [
{name:"你好",playCount:4000},
{name:"它",playCount:400040},
{name:"谁",playCount:200000000},
]
arr.forEach(item=>{
item.playCount = handleNum(item.playCount)
})
console.log(arr);
2、Date
var date = new Date()
var hours = date.getHours()
var minutes = date.getMinutes()
var seconds = date.getSeconds()
var sum = dateTime(hours)+":"+dateTime(minutes)+":"+dateTime(seconds)
function dateTime(num){
if(num<10){
num = "0"+num
}
}
var date
var hours
var minutes
var seconds
setInterval(()=>{
show()
var template = `
<p>${hours}:${minutes}:${seconds}</p>
`
$('body').append(template)
}, 1000);
function show(){
date = new Date()
hours = date.getHours()
minutes = date.getMinutes()
seconds = date.getSeconds()
var sum = dateTime(hours)+":"+dateTime(minutes)+":"+dateTime(seconds)
console.log(sum);
}
function dateTime(num){
if(num<10){
num = "0"+num
}
return num
}
var time = "2021-10-13 17:10:10"
// 多少小时,多少分钟,多少秒
var d = new Date()
// 获取当前时间的毫秒数
//console.log(d.getTime());
var startTime = d.getTime()
//console.log(Date.now());
// 获取活动开始时间的毫秒
var endTime = new Date(time).getTime()
//console.log(endTime);
// 得到中间间隔的毫秒数
var gapTime = endTime - startTime
console.log(gapTime);
var seconds = Math.floor(gapTime/1000)
console.log(seconds);
var hours = Math.floor(seconds/3600)
console.log(hours);
seconds = seconds%3600
console.log(seconds);
var minutes = Math.floor(seconds/60)
console.log(minutes);
seconds = seconds - 60*minutes
console.log(seconds);
var time = "2021-10-19 08:30:00"
var startTime = new Date().getTime()
var endTime = new Date(time).getTime()
var gapTime = endTime-startTime
var minutes = Math.floor(gapTime/(1000*60))
console.log(minutes);
var days = Math.floor(minutes/(60*24))
console.log(days+"天");
minutes = minutes - days*(60*24)
var hours = Math.floor(minutes/60)
console.log(hours+"小时");
minutes = minutes%60
console.log(minutes+"分钟");
function Time(time){
var d = new Date()
var startTime = d.getTime()
var endTime = new Date(time).getTime()
var gapTime = endTime - startTime
console.log(gapTime);
var seconds = Math.floor(gapTime/1000)
console.log(seconds);
var hours = Math.floor(seconds/3600)
console.log(hours+"时");
seconds = seconds%3600
console.log(seconds);
var minutes = Math.floor(seconds/60)
console.log(minutes+"分");
seconds = seconds%60
console.log(seconds+"秒");
}