Harmeet Singh Taara
Harmeet Singh Taara

Reputation: 6611

Java : Convert string to Date

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

Upvotes: 2

Views: 7832

Answers (2)

Zaheer Ahmed
Zaheer Ahmed

Reputation: 28588

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.

Upvotes: 8

namalfernandolk
namalfernandolk

Reputation: 9134

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

Upvotes: 11

Related Questions