Java Sorting Date Field
I have a date like String date='June 02,2013' etc..... I want to Sort the Date field in Ascending and Descending Could any one help? I have tried this to Sort Title field Sort by
Solution 1:
Try this...
Collections.sort(datestring, newComparator<String>() {
DateFormat f = newSimpleDateFormat("MMM dd,yyyy");
@Overridepublic int compare(String o1, String o2) {
try {
return f.parse(o1).compareTo(f.parse(o2));
} catch (ParseException e) {
thrownewIllegalArgumentException(e);
}
}
});
you need to change format of date in the above code.
UPDATED : Updated DateFormat check it..
Post a Comment for "Java Sorting Date Field"