function CompareDates(List: TStringList; Index1, Index2: Integer): Integer;
var
d1, d2: TDateTime;
AFormat, AFormat2: TFormatSettings;
begin
AFormat.DateSeparator := ‘/’;
AFormat.ShortDateFormat := ‘yyyy/mm/dd’;
AFormat2.DateSeparator := ‘-’;
AFormat2.ShortDateFormat := ‘yyyy-mm-dd’;
if Pos(‘/’, LeftStr(List[Index1],10)) > 0 then
d1 := StrToDate(LeftStr(List[Index1],10),AFormat);
if Pos(‘/’, LeftStr(List[Index2],10)) > 0 then
d2 := StrToDate(LeftStr(List[Index2],10),AFormat);
if Pos(‘-’, LeftStr(List[Index1],10)) > 0 then
d1 := StrToDate(LeftStr(List[Index1],10),AFormat2);
if Pos(‘-’, LeftStr(List[Index2],10)) > 0 then
d2 := StrToDate(LeftStr(List[Index2],10),AFormat2);
if d1 < d2 then
Result := -1
else if d1 > d2 then Result := 1
else
Result := 0;
end;
自定義排序:
DateList.CustomSort(CompareDates);
ref:
http://www.swissdelphicenter.ch/en/showcode.php?id=1664
http://hi.baidu.com/caihexi/item/e99ab1154df6e70b8fbde425