Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > SimpleDateFormat Help

Reply
Thread Tools

SimpleDateFormat Help

 
 
Seb
Guest
Posts: n/a
 
      12-16-2004
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.
 
Reply With Quote
 
 
 
 
P.Hill
Guest
Posts: n/a
 
      12-16-2004
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

 
Reply With Quote
 
 
 
 
sebastien_roy@hotmail.com
Guest
Posts: n/a
 
      12-16-2004
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!

 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      12-16-2004
On 16 Dec 2004 11:40:55 -0800, http://www.velocityreviews.com/forums/(E-Mail Removed) 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_gr...omp.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_ugrou p=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
 
Reply With Quote
 
P.Hill
Guest
Posts: n/a
 
      12-16-2004
(E-Mail Removed) 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Date and SimpleDateFormat Kyote Java 16 10-24-2003 11:20 AM
Problems Parsing Date string with SimpleDateFormat Bill Angel Java 4 09-28-2003 01:36 PM
SimpleDateFormat Eric Java 4 09-25-2003 03:16 AM
SimpleDateFormat Slow, Looking to Build or Find Faster One Niko Java 10 09-18-2003 04:19 AM
SimpleDateFormat with Node.getNodeValue Manuel Java 0 08-27-2003 11:17 PM



Advertisments