<!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>
查看一组日期的最大最小的方法
最新推荐文章于 2024-01-26 14:07:21 发布