数组中的最小/最大日期数 [英] Min/Max of dates in an array?
本文介绍了数组中的最小/最大日期数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从日期数组中找出最小和最大日期?目前,我正在创建一个这样的数组:
How can I find out the min and the max date from an array of dates? Currently, I am creating an array like this:
var dates = [];
dates.push(new Date("2011/06/25"))
dates.push(new Date("2011/06/26"))
dates.push(new Date("2011/06/27"))
dates.push(new Date("2011/06/28"))
有没有一个内置的函数来做这个或者我自己写?
Is there a built-in function to do this or am I to write my own?
推荐答案
p>代码使用IE,FF,Chrome进行测试,并且可以正常工作:
Code is tested with IE,FF,Chrome and works properly:
var dates=[];
dates.push(new Date("2011/06/25"))
dates.push(new Date("2011/06/26"))
dates.push(new Date("2011/06/27"))
dates.push(new Date("2011/06/28"))
var maxDate=new Date(Math.max.apply(null,dates));
var minDate=new Date(Math.min.apply(null,dates));
这篇关于数组中的最小/最大日期数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文