简体   繁体   中英

java Calendar get(calendar.MONTH) returns 0

Why does calendar.get(calendar.MONTH) return 0(zero) here: ?

Date date = new SimpleDateFormat("yyyy-mm-dd").parse("2013-02-12");

Calendar calendar = Calendar.getInstance();

calendar.setTime(date);

System.out.println( calendar.get(calendar.MONTH) ); // 0 ??

MM for month and mm minute. Use format - yyyy-MM-dd , you will get desired output which is 1 .

Date date = new SimpleDateFormat("yyyy-MM-dd").parse("2013-02-12");

Got it.. Sorry..

The answer: because I use "mm" but not "MM"

new SimpleDateFormat("yyyy-mm-dd")应该是new SimpleDateFormat("yyyy-MM-dd")

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