1、播放量
<script>
var num = 101000000;
if(num>100000000){
num = num/100000000 + "亿"
}else if(num>=10000){
num = Math.ceil(num/10000)+"万"
}
console.log(num);
</script>
<script>
function handleNum(num){
if (num > 100000000) {
num = num / 100000000 + "亿"
} else if (num >= 10000) {
num = Math.ceil(num / 10000) + "万"
}
return num;
}
var res = handleNum(100000);
console.log(res);
</script>
<script>
function handleNum(num){
if(num>=100000000){
num = num/100000000+"亿"
}else if(num>=10000){
num = num/10000+"万"
}
return num+"";
}
var arr = [
{name:"你好",playcount:4000},
{name:"它",playcount:400040},
{name:"谁",playcount:20000000000}
]
arr.forEach(item=>{
item.playcount = handleNum(item.playcount);
})
console.log(arr)
</script>
1.1、{name: ‘你好’, playCount: ‘4000’}
<script>
function handleNum(num){
if(num>=100000000){
num = num/100000000+"亿"
}else if(num>=10000){
num = num/10000+"万"
}
return num+"";
}
var arr = [
/* 4000 */
{name:"你好",playCount:4000},
/* 40万 */
{name:"它",playCount:400040},
/* 2亿 */
{name:"谁",playCount:200000000}
]
arr.forEach(item=>{
item.playCount = handleNum(item.playCount);
})
console.log(arr)
</script>
2、输入时间
<div id="app"></div>
<script>
setInterval(show,1000)
function show(){
var app = document.getElementById("app");
var d = new Date();
var hours = d.getHours();
var minutes = d.getMinutes();
var seconds = d.getSeconds();
var sum = handleNum(hours) + ":" + handleNum(minutes) + ":" + handleNum(seconds);
console.log(sum);
app.innerHTML = sum;
}
function handleNum(num) {
if (num < 10) {
num = "0" + num;
}
return num;
}
</script>
3、现在时间
<script>
var d = new Date();
var hours = d.getHours();
var minutes = d.getMinutes();
var seconds = d.getSeconds();
var sum = handleNum(hours)+":"+handleNum(minutes)+":"+handleNum(seconds);
console.log(sum)
function handleNum(num){
if(num<10){
num = "0"+num;
}
return num;
}
</script>
4、距离2021-10-13 17:10:10还剩多少时间
<script>
var time = "2021-10-13 17:10:10"
/* 多个小时,多分钟,多少秒 */;
/* 1、获取当前时间的毫秒数 */
var d = new Date();
// console.log(d.getTime())
var startTime = d.getTime();
/* 2、获取活动开始时间的毫秒 */
var endTime = new Date(time).getTime();
// console.log(endTime)
/* 3、得到中间间隔的毫秒数 */
var gapTime = endTime -startTime;
var seconds = Math.floor(gapTime/1000)
console.log(seconds)
var hours = Math.floor(seconds/3600);
console.log(hours)
seconds = seconds - 3600*hours;
var minutes = Math.floor(seconds/60);
console.log(minutes)
seconds = seconds - minutes*60;
console.log(seconds)
/* var time = "2021-10-13 21:30:00" 第一个需求*/
/* var time ="2021-10-19 08:30:00" 还有几天几小时几分 */
</script>
5、分秒时间的换算
<script>
var time = 360000;
/*
66s
*/
/*
一秒
60s 一分钟
60*60 一小时
time/1000 秒
*/
var seconds = Math.floor(time/1000);
console.log(seconds)
var hours = Math.floor(seconds/3600);
console.log(hours)
// seconds = seconds- hours*3600;
seconds = seconds%3600;
console.log(seconds)
var minutes = Math.floor(seconds/60);
console.log(minutes)
seconds = seconds- minutes*60;
console.log(seconds)
</script>
<script>
var time = 306000;
/* 3000
1m = 60s
*/
var seconds = time/1000;
console.log(seconds+"秒")
var minutes = Math.floor(seconds/60);
var seconds = seconds - minutes*60;
console.log(minutes+"分")
console.log(seconds+"余下的秒")
/* 3s */
</script>
<script>
var time = 306150000;
/* 3000
1m = 60s
1h = 60*60s
*/
var seconds = time/1000;
console.log(seconds+"秒")
var hours = Math.floor(seconds/3600);
console.log(hours)
var seconds = seconds%3600;
console.log(seconds)
var minutes= Math.floor(seconds/60);
console.log(minutes)
seconds = seconds%60;
console.log(seconds)
/* 3s */
</script>
6、2021-10-19 08:30:00” 还有几天几小时几分
<script>
/* var time ="2021-10-19 08:30:00" 还有几天几小时几分 */
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));
/*
8201分
1h = 60m
1t = 60*24
*/
// console.log(minutes)
var days = Math.floor(minutes/(60*24));
minutes = minutes -days*(60*24)
console.log(days)
var hours = Math.floor(minutes/60);
console.log(hours)
minutes = minutes - hours*60;
console.log(minutes)
</script>