简体   繁体   中英

Gregorian Calendar - Getting wrong values in Android

I am using Gregorian calendar to set the date value and trying to get the values set. Code below

 Constants.sSetDate_calendar = new GregorianCalendar(year,month,day);// year - 2013, month - 12, day - 15
          Log.w("OOOOO", Constants.sSetDate_calendar.get(Calendar.YEAR)+"--"+Constants.sSetDate_calendar.get(Calendar.MONTH)+"--"+Constants.sSetDate_calendar.get(Calendar.DAY_OF_MONTH)+"");   

In Log statement, i see

11-02 10:21:35.060: W/OOOOO(26671): **2014--0--15**

Not sure what is going wrong. Why the values set and get are different ? Need some help here.

The Calendar class uses a zero-based array meaning January is 0 and December is 11 as can be seen by looking at the Calendar.JANUARY and Calendar.DECEMBER values. The 12th month simply overflows into the next year (December + 1 month) which is why the values change.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM