aspose file tools*
The moose likes Java in General and the fly likes string to date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "string to date" Watch "string to date" New topic
Author

string to date

Naadir Peterson
Ranch Hand

Joined: Sep 22, 2004
Posts: 37
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

Joined: Nov 18, 2003
Posts: 91
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

Joined: Sep 25, 2004
Posts: 156

Hope this will help you out as i am using this.





Love is GOD and GOD is Love.
Anand Karia
IT Concretor.......
M/s. Anand Karia Concreting IT
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
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


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
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.


SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
Cay Horstmann
author
Ranch Hand

Joined: Nov 14, 2004
Posts: 114
    
  10
I agree--the documentation in SimpleDateFormat is pretty bad. The following code works for your specific problem.



Cheers,

Cay


Author of Java 8 for the Really Impatient
Anand Karia
Ranch Hand

Joined: Sep 25, 2004
Posts: 156

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

Joined: Sep 25, 2004
Posts: 156

my above function also contain another function..

Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
It's definitely a lot easier to use SimpleDateFormat, imho.

Layne


Java API Documentation
The Java Tutorial
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: string to date
 
Similar Threads
java.util.Calendar
Parsing error in DaterFormat.parse
how to parse java.util.Date to java.sql.date ?
Parsing date using SimpleDateFormat for hh mm ss
simple date format question