码迷,mamicode.com
首页 > 其他好文 > 详细

setTime

时间:2017-10-12 10:25:07      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:cond   bsp   second   min   settime   time   time()   return   console   

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

标签:cond   bsp   second   min   settime   time   time()   return   console   

原文地址:http://www.cnblogs.com/jayruan/p/7654353.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!