Date fakeDate = sdf.parse("15/07/2013 11:00 AM");
Calendar calendar = Calendar.getInstance()
calendar.setTime(fakeDate);
int currentMonth = calendar.get(Calendar.MONTH);
我得到 currentMonth == 6 而不是 7。
这是为什么?
最佳答案
因为Calendar.MONTH
是从零开始的。 Why ?
检查docs :(总是)
Field number for get and set indicating the month. This is a calendar-specific value. The first month of the year in the Gregorian and Julian calendars is JANUARY which is 0; the last depends on the number of months in a year.
关于java - 为什么用java日历解析时会得到错误的月份,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25350178/