Take the 2-minute tour ×

Say I've got two dates formatted this way:

date1 = Feb 22, 2011
date2 = Mon Feb 21 08:30:03 EST 2011 (default formatting)

will date2.compareTo(date1); still work? I've got a method I'm using to see if certain date values are the same, but its not working. One date is formatted a certain way, and I think this might be problem.

Any insight would be helpful.

share|improve this question
What exactly are you comparing? Two Date instances or two String instances? The Date doesn't store any information about formatting. All it stores is the epoch time in milliseconds. The String in turn knows nothing about the specific information it contains, such as a date representation, the comparison just depends on the natural language rules. –  BalusC Feb 28 '11 at 2:10
They're actually two different dates. I was just printing them like that to ask the formatting question. So confused :s –  maxmackie Feb 28 '11 at 2:17

1 Answer 1

up vote 3 down vote accepted

It will still work. The comparison is based on the milliseconds of the date. The formatting is used for display, not comparison.

In your example, check to be sure that date1 is not at 12:00:00 AM, which would be a different time than date2.

share|improve this answer
Above was just exmaples, I'm not using this data specifically. However, if I can't get the method to work after a little more hacking I'll start a new question with my method. Thanks! –  maxmackie Feb 28 '11 at 1:55

Your Answer


