zoukankan      html  css  js  c++  java
  • 两个日期相减得出天数

    $(function(){
        +function ($, app) {
            function dateDiff(date1, date2) {
                var type1 = typeof date1, type2 = typeof date2;
                if (type1 == 'string')
                    date1 = stringToTime(date1);
                else if (date1.getTime)
                    date1 = date1.getTime();
                if (type2 == 'string')
                    date2 = stringToTime(date2);
                else if (date2.getTime)
                    date2 = date2.getTime();
                //alert((date1 - date2) / (1000*60*60));
                return (date1 - date2) / (1000 * 60 * 60 * 24); //结果是小时
            }
            //字符串转成Time(dateDiff)所需方法
            function stringToTime(string) {
                var f = string.split(' ', 2);
                var d = (f[0] ? f[0] : '').split('-', 3);
                var t = (f[1] ? f[1] : '').split(':', 3);
                return (new Date(
                    parseInt(d[0], 10) || null,
                    (parseInt(d[1], 10) || 1) - 1,
                    parseInt(d[2], 10) || null,
                    parseInt(t[0], 10) || null,
                    parseInt(t[1], 10) || null,
                    parseInt(t[2], 10) || null
                )).getTime();
            }
           // 点击一个按钮,获取两个输入框的值
            $('.day').click(function () {
    //获取值
                var Sdates = $('#s_date').html();
                var Jdates = $('#j_date').html();
    // 带入方法
                t = dateDiff(Jdates, Sdates);
    //回显
                $('.day').html(t+'天');
            });
        }(window.jQuery, window.app);
    });
  • 相关阅读:
    Ubuntu的防火墙UFW
    使用Xshell连接Ubuntu
    Markdown 11种基本语法
    Git Push 避免用户名和密码方法
    "git rm" 和 "rm" 的区别
    无限级分类实现思路
    1. Git 克隆代码
    Git 笔记
    git 远程分支创建与推送
    ci 笔记
  • 原文地址:https://www.cnblogs.com/xiaomili/p/6952879.html
Copyright © 2011-2022 走看看