zoukankan      html  css  js  c++  java
  • 计算天数差、获取当前时间、获取百分比

    //计算天数差
    function getDayNumber(date1, date2) {
    //默认格式为"20030303",根据自己需要改格式和方法
    var year1 = date1.substr(0, 4);
    var year2 = date2.substr(0, 4);
    var month1 = date1.substr(4, 2);
    var month2 = date2.substr(4, 2);

    var day1 = date1.substr(6, 2);
    var day2 = date2.substr(6, 2);

    temp1 = year1 + "/" + month1 + "/" + day1;
    temp2 = year2 + "/" + month2 + "/" + day2;

    var dateaa = new Date(temp1);
    var datebb = new Date(temp2);
    var date = datebb.getTime() - dateaa.getTime();
    var time = Math.floor(date / (1000 * 60 * 60 * 24));
    return time;
    }

    //获取当前时间
    function getNowFormatDate() {
    var date = new Date();
    var seperator1 = ".";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
    month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
    strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
    return currentdate;
    }

    //获取百分比
    function getPercent(num, total) {
    num = parseFloat(num);
    total = parseFloat(total);
    if (isNaN(num) || isNaN(total)) {
    return "-";
    }
    return total <= 0 ? "0%" : (Math.round(num / total * 10000 / 100) + "%");
    }

  • 相关阅读:
    HTML <a> 标签的 target 属性
    CSS display 属性
    test
    ubuntu开启ssh服务
    Ubuntu各个版本的介绍
    Ubuntu和RedHat的区别
    黑苹果Mac系统快捷键修改
    安装Ubuntu 8.04 Server
    VirtualBox虚拟机网络设置(转)
    修改eclipse的背景色(转载)
  • 原文地址:https://www.cnblogs.com/fan-lily/p/5688308.html
Copyright © 2011-2022 走看看