zoukankan      html  css  js  c++  java
  • js利用时间戳动态显示系统时间距指定时间的时间差

    function dateTimes(times) {
    var d = new Date(times * 1000);
    var date = (d.getFullYear()) + "-" + (d.getMonth() + 1) + "-" + (d.getDate()) + "-" + (d.getHours()) + ":" + (d.getMinutes()) + ":" + (d.getSeconds());
    var startTime = date;
    var currTime = new Date(); //当前时间
    //将xxxx-xx-xx的时间格式,转换为 xxxx/xx/xx的格式
    startTime = startTime.replace(/-/g, "/");
    var sTime = new Date(startTime);
    var totalTime = currTime.getTime() - sTime.getTime();
    var days = parseInt(totalTime / parseInt(1000 * 60 * 60 * 24));
    totalTime = totalTime % parseInt(1000 * 60 * 60 * 24);
    var hours = parseInt(totalTime / parseInt(1000 * 60 * 60));
    totalTime = totalTime % parseInt(1000 * 60 * 60);
    var minutes = parseInt(totalTime / parseInt(1000 * 60));
    totalTime = totalTime % parseInt(1000 * 60);
    var seconds = parseInt(totalTime / parseInt(1000));
    var time = "";
    if (days >= 1) {
    time = days + "天" ;
    } else if (hours >= 1) {
    time = hours + "时";
    } else if (minutes >= 1) {
    time = minutes + "分"
    } else {
    time = seconds + "秒";
    }
    return time;

    }

  • 相关阅读:
    第七讲 宋词:婉约之曲与豪放之声
    P2024 食物链
    可以吹一年的事
    信息传递
    11.11模拟赛总结(又名斗地主战记)
    11.9模拟赛总结
    扩展欧几里得(exgcd模板)
    发糖果(拓扑排序模板)
    高斯消元
    关于我
  • 原文地址:https://www.cnblogs.com/pangbo1213/p/8617490.html
Copyright © 2011-2022 走看看