• 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

Date parsing issue

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know why this happens but when I attempt to parse certain dates they are not parsed correctly. Take the following example.



The output I get by setting the leniency to true in the DateFormat is:

Date 1: Sun Jan 06 03:00:00 EDT 1974
Date 2: Sun Jan 06 03:00:00 EDT 1974




Now if I set the leniency to false I get the following:

java.text.ParseException: Unparseable date: "197401060200"
at java.text.DateFormat.parse(DateFormat.java:337)
at main.main(main.java:16)
Date 1: null
Date 2: Sun Jan 06 03:00:00 EDT 1974




The application I am working on will get a use the ResultSet getTimeSpamp() method to create a java.util.Date. I get the same behavior from this as well. I only discovered this because I have duplicate dates where I shouldn't have. I have counted 33 occurrences from 1974-2009. Does anyone know why this happens? Thanks.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That sounds really strange. I copied and pasted your code and ran it, and got the following output, which is exactly what I expected:

Date 1: Sun Jan 06 02:00:00 CET 1974
Date 2: Sun Jan 06 03:00:00 CET 1974


And when I set leniency to false, I get the same result.

I tested this with Sun Java 6 update 7 on Ubuntu. Which version of Java are you using on what OS?
 
Adam J Smith
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java 1.6.0_11
Windows Vista
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Adam J Smith wrote:Java 1.6.0_11
Windows Vista


And your timezone isn't CET, is it? Perhaps you should look at those 30-something instances of duplicate times and see whether there's a pattern.
 
Adam J Smith
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just tried it on a Solaris box with Java 1.6.0_11 and Java 1.6.0_13. It worked correctly. Thanks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic