[英]SimpleDateFormat.parse()
SimpleDateFormat.parse()
accepts the date 003/1/2011
when the format is MM/dd/yyyy
.当格式为MM/dd/yyyy
时, SimpleDateFormat.parse()
接受日期003/1/2011
。 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
.并且日期被解析为00/11/2011
。 What is wrong?怎么了?
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
.那是MM/dd/yyyy
中的03/01/2001
。 Seems right?看起来对吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.