Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to convert a String to date
07-10-2008, 07:55 PM
Post: #1
How to convert a String to date
How do I convert a String to date?
Find all posts by this user
Quote this message in a reply
07-10-2008, 08:59 PM
Post: #2
RE: How to convert a String to date
What is your date format? You can use the SimpleDateFormat for doing it.
Visit this user's website Find all posts by this user
Quote this message in a reply
07-10-2008, 09:01 PM
Post: #3
RE: How to convert a String to date
Converting a string to date is easy

[java]
String date ="01/21/2008";
Date dt = new Date(date);
System.out.println(dt);
[/java]
Find all posts by this user
Quote this message in a reply
07-10-2008, 09:06 PM
Post: #4
RE: How to convert a String to date
My String contains date in the below format.

21.1.2008.

programmer, I tried with the you said. It is throwing me an IllegalArgumentException.
Find all posts by this user
Quote this message in a reply
07-10-2008, 09:09 PM
Post: #5
RE: How to convert a String to date
[java]
String date ="21.1.2008";
SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy");
Date dt = format.parse(date);
System.out.println(dt);
[/java]

Try the above code.
Visit this user's website Find all posts by this user
Quote this message in a reply
07-10-2008, 09:34 PM
Post: #6
RE: How to convert a String to date
Sorry my code will work only if the date format is dd/mm/yyyy. The SimpleDateFormat is the right choice to go
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)