Java SimpleDateFormat提供解析错误

day*_*mer 1 java date

我正在做以下事情

SimpleDateFormat formatter = new SimpleDateFormat("MM-dd-yyyy"); calendar.setTime(formatter.parse( "2012年1月26日");

当我做

calendar.getTime()

我知道了

java.text.ParseException:无法解析的日期:"01/26/2012"

我做错了什么?

谢谢

Bri*_*ach 6

呃,你给出的模式

MM-dd-yyyy
Run Code Online (Sandbox Code Playgroud)

SimpleDateFormat再提供它

01/26/2012
Run Code Online (Sandbox Code Playgroud)

要解析.这不是你指定的格式,它告诉你它无法解析它.

你需要:

SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy"); 
Run Code Online (Sandbox Code Playgroud)