aspose file tools*
The moose likes Beginning Java and the fly likes String to Date Convertion with JDK 1.4.2 and JDK 5.0 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String to Date Convertion with JDK 1.4.2 and JDK 5.0" Watch "String to Date Convertion with JDK 1.4.2 and JDK 5.0" New topic
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: 8718
    
    6

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...
 
Consider Paul's rocket mass heater.
 
subject: String to Date Convertion with JDK 1.4.2 and JDK 5.0
 
Similar Threads
Help for using Java Time
weird java dates!!!!
TimeZone Conversion
Convert Local time to UTC and vice versa
Converting from GMT to Local Timezone using two seperate fields (date & time).