user2120794
user2120794

Reputation: 5

not getting proper date while parsing String date to Date

DateFormat formatter = new SimpleDateFormat("yy-mm-dd");
formatter.setLenient(false);
String[] dateStr = { "2013-12-27", "2013-01-03"};
for (int i = 0; i <= 1; i++) {
     Date date = formatter.parse(dateStr[i]);
     System.out.println("date is "+date);
}

result : Sun Jan 27 00:12:00 IST 2013

Thu Jan 03 00:01:00 IST 2013

i am parsing string date in to Date.but it is giving me date Starting with month Jan regardless of what month i am passing to formatter constructor.

Upvotes: 0

Views: 128

Answers (3)

Evan Knowles
Evan Knowles

Reputation: 7511

The format for your date would be yy-MM-dd. Update your format and check.

Upvotes: 4

A.Goutam
A.Goutam

Reputation: 3494

once Silly Mistake

DateFormat formatter = new SimpleDateFormat("yy-MM-dd");

Format this line in your code

Upvotes: 3

BobTheBuilder
BobTheBuilder

Reputation: 19304

mm for minutes MM for month

Use: "yy-MM-dd"

See here

Upvotes: 4

Related Questions