Please use real words when posting to the forums. Abbreviations such as "diff" in place of "difference" only serve to make your posts more difficult to read and less likely to generate useful responses.
David Newton wrote:I can't reproduce this; if I have different dates, I don't get 0 for the difference between the times.
Agreed. If the two days were only a day apart, then I would have made the argument that maybe the hours, minutes, and seconds, along with rounding down, may be the cause. But the example given is a month apart... something else is happening here.
Maybe you can show us the code that initializes dat1 and dat2?
java.util.Date dat1,dat2 ;
formatter = new SimpleDateFormat("yy-mmm-dd");
dat1 = (java.util.Date)formatter.parse("2010-11-22");
dat2 = (java.util.Date)formatter.parse("2010-12-22");
Here lies your problem. The lower case 'm' stands for minutes, not month. You should use upper case 'M' instead. And you should only use two 'M's, not three, since three (ie 'MMM') means the month spelled out as a word instead of a number.
Try this instead:
As a tip for future troubleshooting. When you encounter problems, always try to print out the different variable values in your code, to see if they are what you expect. If you would have printed out the dat1 and dat2 values you would have seen that the dates were wrong, thus you would know that the bug is in the parsing of the date.