zoukankan      html  css  js  c++  java
  • 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));

  • 相关阅读:
    ant
    hudson
    【消息队列MQ】各类MQ比较
    日本出行
    使用Eclipse Installer安装Eclipse
    Firebug控制台详解
    浮动
    CSS3
    HTML制作视频简介
    使用I/O流复制指定文件
  • 原文地址:https://www.cnblogs.com/jayruan/p/7654353.html
Copyright © 2011-2022 走看看