SimpleDateFormat Help

Discussion in 'Java' started by Seb, Dec 16, 2004.

  1. Seb

    Seb Guest

    Hello,

    I have an old database which had multiple dates stored in it.
    Unfortunately, there were no fixed format for these dates and I now
    have to standardize everything. In the past, I used to create a Date
    object using the Date(String) constructor in order to parse the string
    containing the date, since this constructor could recognize a date in
    (almost) any format. Unfortunately, this constructor is now
    deprecated and I want to use a non-deprecated method.

    I tried to use the suggested replacement to this constructor, which is
    the DateFormat.parse(String) method, but this method requires that we
    specify the date format before parsing the date. As I mentioned
    previously, I don't know the format of the field and don't really know
    what to use anymore.

    Any help would be more than welcome.

    thanks in advance.
     
    Seb, Dec 16, 2004
    #1
    1. Advertising

  2. Seb

    P.Hill Guest

    Seb wrote:
    > there were no fixed format for these dates and I now
    > have to standardize everything. [...]
    >
    > I tried to use the suggested replacement to this constructor, which is
    > the DateFormat.parse(String) method, but this method requires that we
    > specify the date format before parsing the date.


    What you need is DateFormat which tries a series of Simple Date Formats.
    If you such a class, I posted one called MultiDateFormat years ago on
    this list or I could send it to you.

    The trick is NOT the code, but putting the series of candidate formats
    in order so that you don't inappropriately mis-identify a date;
    01/01/2001 is ambiguous not matter what order you list mm/dd/yyyy or
    dd/mm/yyyy.

    -Paul
     
    P.Hill, Dec 16, 2004
    #2
    1. Advertising

  3. Seb

    Guest

    Paul,

    I thought there was actually a class that did it and that I couldn't
    find it. Thanks for your help. The problem with my database is that
    in addition to the multiple date formats (yyyy/MM/dd, MM/dd/yyyy,
    dd/MM/yyyy), I also have multiple date separators. I would really
    appreciate if you could send me your class whether by re-posting it or
    by sending it by e-mail. I think re-posting it would be the best
    solution.

    Thanks a lot for your help!
     
    , Dec 16, 2004
    #3
  4. On 16 Dec 2004 11:40:55 -0800, wrote:

    > ..I think re-posting it would be the best solution.


    I think you would be better off learning how to use a search engine...

    For instance Google groups advanced search for java groups..
    http://groups.google.com/advanced_group_search?q=group:comp.lang.java*

    Plug in the source title as 'exact phrase'
    and 'author's last name and out pops..
    <http://groups-beta.google.com/groups?as_epq=MultiDateFormat&safe=images&as_ugroup=comp.lang.java*&as_uauthors=hill&lr=&hl=en>

    --
    Andrew Thompson
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.PhySci.org/ Open-source software suite
    http://www.1point1C.org/ Science & Technology
    http://www.LensEscapes.com/ Images that escape the mundane
     
    Andrew Thompson, Dec 16, 2004
    #4
  5. Seb

    P.Hill Guest

    wrote:

    > The problem with my database is that
    > in addition to the multiple date formats (yyyy/MM/dd, MM/dd/yyyy,
    > dd/MM/yyyy), I also have multiple date separators.


    So how DO expect to differentiate 1-12 followed by 1-12 in the first
    and second fields? That is certainly a problem.

    -Paul
     
    P.Hill, Dec 16, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Manuel
    Replies:
    0
    Views:
    557
    Manuel
    Aug 28, 2003
  2. Niko
    Replies:
    10
    Views:
    2,471
    Wojtek
    Sep 18, 2003
  3. Eric

    SimpleDateFormat

    Eric, Sep 24, 2003, in forum: Java
    Replies:
    4
    Views:
    9,563
    Chris Smith
    Sep 25, 2003
  4. Bill Angel
    Replies:
    4
    Views:
    1,359
    Bill Angel
    Sep 28, 2003
  5. Kyote
    Replies:
    16
    Views:
    4,180
    Michael Borgwardt
    Oct 24, 2003
Loading...

Share This Page