1

I am parsing a date, where I am passing 2011-02-10 00:00:00:0, and I am getting 2011-01-10 as the result. Is this wrong? Please help.

 DateFormat df = new SimpleDateFormat("yyyy-mm-dd");
 today = df.parse(datecollection);
2
  • 1
    what does datecollection contains, and is "parasing", "parsing"? Commented Feb 11, 2011 at 7:39
  • @robobooga fixed format/grammar Commented Feb 11, 2011 at 7:48

4 Answers 4

3

The pattern for month is MM: yyyy-MM-dd. You should read the API doc.

Sign up to request clarification or add additional context in comments.

Comments

1

You should be using MM not mm. MM is for month, mm is for minute

Comments

1

try using MM instead of mm should work

refer http://download.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html

 M  Month in year   Month   July; Jul; 07
 m  Minute in hour  Number  30

an example

"yyyy-MM-dd HH:mm:ss:SSS"   2001-07-04 12:08:56:235

Comments

0

You need to replace mm with MM. Please take a look at this page.

try
   {
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); 
            System.out.println(df.parse("2011-02-10 00:00:00:0"));
   }
   catch (Exception e){}

Prints:

Thu Feb 10 00:00:00 CET 2011

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.