Lai*_*Lai 0 java calendar date simpledateformat
谁能帮我理解为什么我得到不同的月份值
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
System.out.println(dateFormat.format(cal.getTime())
+ "--"
+ cal.get(Calendar.MONTH));
Run Code Online (Sandbox Code Playgroud)
令人惊讶地显示
09/09/2012--8
Run Code Online (Sandbox Code Playgroud)
在Calendar课堂上,MONTH从index开始0。因此,January为0,February为1,因此September为8。
PS: -这是真的,这是一个Inconsistency在Calendar一流的,所以我建议你看一看Joda-Time API,让您的生活更轻松与日期时间数据工作时。