JAVA GregorianCalendar add方法存在bug
- 摘要:GregorianCalendargc=newGregorianCalendar(TimeZone.getTimeZone("GMT"));SimpleDateFormatforamt=newSimpleDateFormat("yyyy-MM-dd");Dated=foramt.parse("2014-02-01");gc.setTime(d);System.out.println(foramt.format(gc.getTime()));gc.setTimeInMillis(d
- 标签:方法 Java RIA
GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
SimpleDateFormat foramt = new SimpleDateFormat("yyyy-MM-dd");
Date d = foramt.parse("2014-02-01");
gc.setTime(d);
System.out.println(foramt.format(gc.getTime()));
gc.setTimeInMillis(d.getTime());
gc.add(Calendar.MONTH, 1);
System.out.println(foramt.format(gc.getTime()));
gc.add(Calendar.MONTH, 1);
System.out.println(foramt.format(gc.getTime()));
gc.add(Calendar.MONTH, 1);
System.out.println(foramt.format(gc.getTime()));
The result is :
2014-02-01
2014-03-01
2014-03-29 (it should be 2014-04-01)
2014-04-29
这是JAVA本身的bug ,已经确认在最新的jdk1.8.0_05 中仍然存在。
mail : longbow.liu@carel.com