Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SimpleDateFormat.parse()

Tags:

java

SimpleDateFormat.parse() accepts the date 003/1/2011 when the format is MM/dd/yyyy. Trying with code below:

SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
sdf.setLenient(false);
Date dt2;
try
{
    dt2 = sdf.parse(_datemmddyyyy);
}
catch (ParseException e)
{
    return false;
}

and the date is parsed as 00/11/2011. What is wrong?

like image 720
Sukinal Navin Avatar asked Apr 02 '26 01:04

Sukinal Navin


1 Answers

Are you sure? This:

SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
sdf.setLenient(false);
Date dt2 = sdf.parse("003/1/2011");
System.out.println(dt2);

Yields:

Tue Mar 01 00:00:00 PST 2011

That's 03/01/2001 in MM/dd/yyyy. Seems right?

like image 133
WhiteFang34 Avatar answered Apr 03 '26 18:04

WhiteFang34