SimpleDateFormat problems. I'm perplexed...

Dear all!

I'm having trouble with the SimpleDateFormat class (jdk1.5.0_04). When set to "lenient" it returns the wrong date. When lenient is set false(i.e. strict) it throws an exception. Pls have a look at my code:

publicstaticvoid main(String[] args){

try{

DateFormat formatter =new SimpleDateFormat("yyyy.MM.dd HH:mm");

formatter.setLenient(false);

Date date = (Date)formatter.parse("2006.03.26 02:15");

System.out.println(date);

}catch (ParseException e){

e.printStackTrace();

}

}

The above will throw a ParseException telling me that the date "2006.03.26 02:15" is unparseable.

When I set lenient to "true" it returns "Sun Mar 26 03:15:00 CEST 2006". The time is set to "03:15" which is clearly wrong. This seems to be a problem when the time portion is 02 (for other times it works!!)

What am I missing?

Any help is appreciated.

Best regards!

[1396 byte] By [acsko2a] at [2007-10-2 17:11:04]
# 1

I tried your code. Whether I have lenient set to true or false it outputs Sun Mar 26 02:15:00 BST 2006If you were genuinely running the code you thought you were rather than an out-of-date version, I'd be inclined to suspect that locales were the root problem. I should note, though, that I tried using locales en-us and es-co (as opposed to my default en-gb) and neither made any difference.

YAT_Archivista at 2007-7-13 18:26:06 > top of Java-index,Desktop,I18N...
# 2
Hello!Thanks for having a look. My default locale is hu_HU (Hungarian).I'll have a bit of a play with other locales, but my default locale did really produce the results according to my last post... :)Best regards!
acsko2a at 2007-7-13 18:26:06 > top of Java-index,Desktop,I18N...
# 3
I tested hu_HU and it still works for me, so I think it must be something else.
YAT_Archivista at 2007-7-13 18:26:06 > top of Java-index,Desktop,I18N...
# 4

May I suggest that in CEST, daylight saving time begins at 0200 on Sunday March 26 and so there is no such time as 02:15 on that day? So the only reasonable thing for the code to do is to return 03:15? And that in BST, some other DST rules apply? Locales would have nothing to do with this, I don't believe.

DrClapa at 2007-7-13 18:26:06 > top of Java-index,Desktop,I18N...
# 5
Absolutely. As I realised (of course only after posting my perplexed message :) daylight savings indeed started on 2006.03.26 at 02:00 in the morning. I'll be looking out for this next time around :)Thanx for the replies.Regards!
acsko2a at 2007-7-13 18:26:06 > top of Java-index,Desktop,I18N...