• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

String to Date Convertion with JDK 1.4.2 and JDK 5.0

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Karl Weber
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
reply
    Bookmark Topic Watch Topic
  • New Topic