Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need to parse a date from a String.

 
Tontang Bei
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try looking at SimpleDateFormat ?
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic