setTime

Posted jayruan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了setTime相关的知识,希望对你有一定的参考价值。

var getTime = function() {
var _ = [‘00‘, ‘01‘, ‘02‘, ‘03‘, ‘04‘, ‘05‘, ‘06‘, ‘07‘, ‘08‘, ‘09‘], //补零
d = new Date(),
h = d.getHours(),
m = d.getMinutes(),
s = d.getSeconds();
setTimeout(function(){
console.log(getTime());
}, 1000);

return [_[h] || h, _[m] || m, _[s] || s].join(":");

}
setTimeout(function(){
console.log(getTime());
}, 1000);

 

 =============================

function startit(h=0,m=0,s=0){
var _ = [‘00‘, ‘01‘, ‘02‘, ‘03‘, ‘04‘, ‘05‘, ‘06‘, ‘07‘, ‘08‘, ‘09‘];
s++;
if(s>=60){
s = 0;
m++;
}
if(m>=60){
m = 0;
h++;
}
console.log([_[h] || h, _[m] || m, _[s] || s].join(":"));
setTimeout("startit("+h+","+m+","+s+")", 1000);
}
startit(1,1,28);

 

===============

var start=new Date("2002-01-10 09:33:10");
var end=new Date("2002-01-10 10:00:00");
function formatTime(seconds) {
var min = Math.floor(seconds / 60),
second = seconds % 60,
hour, newMin, time;

if (min > 60) {
hour = Math.floor(min / 60);
newMin = min % 60;
}

if (second < 10) { second = ‘0‘ + second;}
if (min < 10) { min = ‘0‘ + min;}
return time = hour? (hour + ‘:‘ + newMin + ‘:‘ + second) : (min + ‘:‘ + second);
}
console.log(formatTime((end-start)/1000));

以上是关于setTime的主要内容,如果未能解决你的问题,请参考以下文章