查看一组日期的最大最小的方法

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script>
//var test=Math.max(5,7)
    var testMaxOrmin={
         maxOrMin: function(max) {
            var dt = max ? 0: Number.MAX_VALUE,
                i = 0,
                args = arguments[1],
                ln = args.length;

            for (; i < ln; i++) {
                dt = Math[max ? 'max': 'min'](dt, args[i].getTime());
            }
            return new Date(dt);
        },
        max: function() {
            return this.maxOrMin.apply(this, [true, arguments]);
        },

        /**
         * Returns the minimum date value passed into the function. Any number of date
         * objects can be passed as separate params.
         * @param {Date} dt1 The first date
         * @param {Date} dt2 The second date
         * @param {Date} dtN (optional) The Nth date, etc.
         * @return {Date} A new date instance with the earliest date value that was passed to the function
         */
        min: function() {
            return this.maxOrMin.apply(this, [false, arguments]);
        }
    }
    alert(testMaxOrmin.max(new Date("2009-02-03") ,new Date("2019-02-03"),new Date("2029-02-03"),new Date("2039-02-03")));
</script>
</head>
<body>


</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值