*
The moose likes Java in General and the fly likes Need to parse a date from a String. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Need to parse a date from a String." Watch "Need to parse a date from a String." New topic
Author

Need to parse a date from a String.

Tontang Bei
Ranch Hand

Joined: Oct 21, 2006
Posts: 130
Hello,
I need to parse a date from a String. Ive been checking the APis and everything seems so deprecated. I cant figure out how to do this Any pointers?
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3493
    
  13
Did you try looking at SimpleDateFormat ?


Joanne
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Hi Bei,

I noticed, this is your 100th post. So you're expected to open a bottle of wine.

One of the classes you need is java.text.SimpleDateFormat
(see Where your java is /Java/docs/api/java/text/SimpleDateFormat.html)
The document also shows what letter means what (e.g. that big M meand month and small m means minute)

An example:


Prints:
Fri May 04 00:00:00 CEST 2007 <- my time zone, Yours, Bu.
05-04-2007
Tontang Bei
Ranch Hand

Joined: Oct 21, 2006
Posts: 130
Hi Bu,
Thanks for the explanation. I have also implemented something pretty much the same in my program. But now I have to so some date arithmetic on it. any ideas on that? I basically have to compare 2 dates I guess I will have to parse the month, the date and the year from the Date object.(Is that possible?) Is there another way to do this?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Need to parse a date from a String.