我想使用Java脚本从3个日期(8/1 / 2011,6 / 1 / 2011,7 / 1/2011)中找到最小日期,格式为(mm / dd / yyyy)。
最佳答案
未经测试的代码,但是您应该明白这一点!
// Initialise an array of dates, with correct values
// You want 3 dates, so put them in here
var MyDates= New Array('15/10/2000','28/05/1999','17/09/2005');
// A function that takes an array of dates as its input
// and returns the smallest (earliest) date
// MUST take at LEAST 2 dates or will throw an error!
function GetSmallestDate(DateArray){
var SmallestDate = new Date(DateArray[0]);
for(var i = 1; i < DateArray.length; i++)
{
var TempDate = new Date(DateArray[i]);
if(TempDate < SmallestDate)
SmallestDate = TempDate ;
}
return SmallestDate ;
}
// Call the function!
alert(GetSmallestDate(MyDates));
关于javascript - 如何使用JavaScript函数从3个日期中查找最小日期?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5728746/