SimpleDateFormat Help

S

Seb

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.
 
P

P.Hill

Seb said:
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
 
S

sebastien_roy

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!
 
P

P.Hill

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top