permaculture playing cards*
The moose likes Java in General and the fly likes Conversion of String to Date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Conversion of String to Date" Watch "Conversion of String to Date" New topic
Author

Conversion of String to Date

Sham Grandhe
Ranch Hand

Joined: Dec 16, 2003
Posts: 73
Hi Friends,
This is shyam Kumar, in a project i need to take the date from the user and convert it to Date format. Can some one Help me in converting a date in String format to java.util.Date format .
thank you

regards
shyam
[ December 09, 2004: Message edited by: kumar shyam ]
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Read the API JavaDocs, specifically java.util.DateFormat and java.util.SimpleDateFormat. You should be able to work it out from there.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Sham Grandhe
Ranch Hand

Joined: Dec 16, 2003
Posts: 73
Hi Paul Sturrock,
thank you for advice, but ive done all that finally come to the fourm. there is a way that we can convert the Date in String format to Date but the String must be in specific format only ie for ex Aug 16, 1981. .
What I want is that, I must be able to give date in a any of the String format and able to build a Date object. ( MM/dd/yyyy, yyyy/mm/dd or dd/mm/yyyy or mm/dd/yy).
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Parsing a String to a Date where the date can be in any valid Date format is a big task. The API comes with SimpleDateFormat which is (as you can probably gather from the name) a simple extension of the abstract class DateFormat. One SimpleDateFormat object has only one date format, if you follow. What you need is to write your own extension of DateFormat so it can accept an array of formats. Any this is where it gets difficult - how do you actually workout what is a date? You need to define an complete list of formats your program can accept and have your DateFormat class's parse method handle them all.
Sham Grandhe
Ranch Hand

Joined: Dec 16, 2003
Posts: 73
Hi Paul,
Thank you for your suggestion, any how iam doing the same thing using three combo boxes. and validating them in the same manner.
bye bye
have a nice day

shyam
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Conversion of String to Date
 
Similar Threads
JDBC SQL server date format problem
simple date format question
Signature of main
how to convert String into Date format
Difficulty assigning Java Util Date to TemporalType field in Entity Bean