Hi i have the following datetime objects
E.g. like
25/06/2012, 11:45 AM
25/06/2012, 12:00 AM
25/06/2012, 12:15 AM
I expecting the sorting order to be exactly like above using the comparator class method
But however it return me with a result like below:
Can anyone advise what should be the correct comparable method to be used?
25/06/2012, 12:00 AM
25/06/2012, 12:15 AM
25/06/2012, 11:45 AM
Your comparator is already giving the logical result. 12:00 AM is midnight, and comes before 11:45 AM.
Midday is 12:00 PM, which then comes before 1:00 PM.
I would certainly hope that’s the ordering you want, even though it’s not the lexicographic order of this particular representation. (If you use a 24-hour representation instead of 12-hour + am/pm designator, it’s a lot clearer.)