JavaScript练习题 | 计算两个日期的天数差(1)

题目地址:https://github.com/iszu/web-learning/blob/master/JavaScript%E7%BB%83%E4%B9%A0%E9%A2%98.md

 

        function daySpan(date1, date2) {
            var t = date2.getTime() - date1.getTime();
            t = Math.abs(t) / (1000 * 60 * 60 * 24);
            console.log(t);

        }
        daySpan(new Date(2016, 2, 7), new Date(2016, 4, 12))     // 66
        daySpan(new Date(2016, 4, 12), new Date(2016, 2, 7))     // 66

 

posted @ 2020-09-10 11:37  huluxin  阅读(154)  评论(0编辑  收藏  举报