2

i try to convert string to date , but when after the conversion the month is set to jan , but in input the month is other example 'sep' . following is my code.

Date tempDate = new SimpleDateFormat("mm/dd/yyyy").parse("09/12/2014");
System.out.println("Current Date " +tempDate);

output :

Current Date Sun Jan 12 00:09:00 IST 2014
1
  • This comes up every week, using the wrong format string. Commented Feb 15, 2013 at 5:28

2 Answers 2

11

it is MM/dd/yyyy. not mm/dd/yyyy

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

Comments

8

Reference these formats Java Date Format Docs:

Formats for datetime

so mm is to reference minutes in hour while MM is for Month.

That is the reason you are getting:

Current Date Sun Jan 12 00:09:00 IST 2014 from ("09/12/2014")

by default month is Jan while it set minutes to '09' due to mm.

1 Comment

+1, all future questions like this should be linked this answer. you should include a reference to the javadoc though.

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.