Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

string to date

 
Naadir Peterson
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..

How do i convert a string (12 July 2004) to a date? the DateFormat's
parse() method is confusing. coz i can only parse a date in this format (12/12/2003) and gives me sum weird date back.

thanx
 
Greg T Robertson
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take another look at the API docs regarding DateFormat and more importantly SimpleDateFormat

there are patterns to use there it is very flexible
 
Anand Karia
Ranch Hand
Posts: 156
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hope this will help you out as i am using this.



 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But in fact you need to write your own method: val_int, isnt it?

Thus, it seems that we need to write our conversion code anyway.

Nick
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Naadir Peterson:
Hi..

How do i convert a string (12 July 2004) to a date? the DateFormat's
parse() method is confusing. coz i can only parse a date in this format (12/12/2003) and gives me sum weird date back.

thanx


DataFormat or SimpleDateFormat are good way to solve your problem, BUT you must see posibly pattern of date in java doc.
 
Cay Horstmann
author
Ranch Hand
Posts: 172
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree--the documentation in SimpleDateFormat is pretty bad. The following code works for your specific problem.



Cheers,

Cay
 
Anand Karia
Ranch Hand
Posts: 156
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OH i forget to write val_int function. here it is.




hope this would work out.....

I also agree with cay response....
 
Anand Karia
Ranch Hand
Posts: 156
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my above function also contain another function..

 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's definitely a lot easier to use SimpleDateFormat, imho.

Layne
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic