| Author |
String to Date Convertion with JDK 1.4.2 and JDK 5.0
|
Karl Weber
Greenhorn
Joined: Aug 08, 2008
Posts: 3
|
|
Hi there, I have the following problem with converting a String to a Date. While my code segment worked just fine with jdk 1.4.2 I have problems migrating this code to jdk 5.0. Here is the code which worked just fine with jdk 1.4.2: private static Date convertStringToDate(String text) throws ParseException { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); simpleDateFormat.setLenient(false); Date date = simpleDateFormat.parse(text); return date; } // StringToDate Passing this function a text = "2006-11-20T15:16:24.000+0000" resulted in no exceptions (my timezone is "Europe/Berlin"). Running this function under JDK 5.0 throws the following exception: java.text.ParseException: Unparseable date: "2006-11-20T15:16:24.000+0000" I believe that the cause of the problem are the last 5 digits of the text - string in combination with the current timezone. That seems to have changed since jdk 1.4.2. My problem now is that I just get a string like the one above and want to convert it to a date without setting a prober timezone (just like running this code under jdk 1.4.2). How can I accopmplish this under jdk 1.5? Thanks in advance for any answers... [ August 09, 2008: Message edited by: Karl Weber ] [ August 09, 2008: Message edited by: Karl Weber ] [ August 09, 2008: Message edited by: Karl Weber ]
|
 |
Joe Ess
Bartender
Joined: Oct 29, 2001
Posts: 8264
|
|
Welcome to the JavaRanch. I've heard others complain of a change in the way date formats were handled in 1.4 and 1.5, but I didn't pursue it further.
|
"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
|
 |
Karl Weber
Greenhorn
Joined: Aug 08, 2008
Posts: 3
|
|
Originally posted by Joe Ess: Welcome to the JavaRanch. I've heard others complain of a change in the way date formats were handled in 1.4 and 1.5, but I didn't pursue it further.
Thanks for the link...
|
 |
Karl Weber
Greenhorn
Joined: Aug 08, 2008
Posts: 3
|
|
Actually this problem occured in combination with IBM Websphere (as mentioned in the linked post). Currently I'm using RAD (Rapid Application Developer) 6 which works with JDK 1.4.2 and RAD 7 which works with JDK 5.0. But because the SimpleDateFormat - class is from the package java.text I believe that the problem is not IBM related but is JDK - specific...
|
 |
 |
|
|
subject: String to Date Convertion with JDK 1.4.2 and JDK 5.0
|
|
|