How to convert a formated date "2001/03/09" as String object that is "YYYY/MM/DD" into a java.util.Date object.
fa.
-
How to convert String into java.util.Date (6 messages)
- Posted by: Farhan Alam
- Posted on: March 17 2001 12:10 EST
Threaded Messages (6)
- How to convert String into java.util.Date by Rick Grashel on March 18 2001 13:22 EST
- MM not mm by Stefan Avigue on June 11 2009 14:02 EDT
- Re: MM not mm by Sai Kiran on July 09 2009 03:04 EDT
- MM not mm by Stefan Avigue on June 11 2009 14:02 EDT
- How to convert String into java.util.Date by Prasath Balakrishnan on March 18 2001 16:40 EST
- How to convert String into java.util.Date by Keith McRae on March 19 2001 03:21 EST
- Remember that SDF is not thread-safe by Javin Paul on December 03 2014 11:19 EST
- How to convert String into java.util.Date by Keith McRae on March 19 2001 03:21 EST
-
How to convert String into java.util.Date[ Go to top ]
- Posted by: Rick Grashel
- Posted on: March 18 2001 13:22 EST
- in response to Farhan Alam
import java.text.*;
import java.util.*;
public class DateFormatTest
{
public DateFormatTest()
{
String dateString = "2001/03/09";
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/mm/dd");
Date convertedDate = dateFormat.parse(dateString);
System.out.println("Converted string to date : " + convertedDate);
}
public static void main(String[] argv)
{
new DateFormatTest();
}
}
} -
MM not mm[ Go to top ]
- Posted by: Stefan Avigue
- Posted on: June 11 2009 14:02 EDT
- in response to Rick Grashel
The Format String should be SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd"); Upper case MM represents month... lower case mm means minutes. -
Re: MM not mm[ Go to top ]
- Posted by: Sai Kiran
- Posted on: July 09 2009 03:04 EDT
- in response to Stefan Avigue
Thank you Stefan Avigue for the reply, I was really struggling for why the format is getting wrong. -
How to convert String into java.util.Date[ Go to top ]
- Posted by: Prasath Balakrishnan
- Posted on: March 18 2001 16:40 EST
- in response to Farhan Alam
I feel u can use the toString() directly after having obtained the date from the Collections package from the java.util.Date itself.
See if it works.
Prasath -
How to convert String into java.util.Date[ Go to top ]
- Posted by: Keith McRae
- Posted on: March 19 2001 03:21 EST
- in response to Prasath Balakrishnan
-
Remember that SDF is not thread-safe[ Go to top ]
- Posted by: Javin Paul
- Posted on: December 03 2014 11:19 EST
- in response to Keith McRae
It's not easy to convert String to date in multi-threading environment, because SimpleDateFormat is not thread-safe. See this tutorial to learn how we can use SimpleDateFormat safely to convert String to Date in Java.