java - Calendar dont work as expected -
i using calendar api think wrong
calendar cal = new gregoriancalendar(timezone.getdefault()); cal.add(calendar.year, 2015); cal.add(calendar.month, 6); cal.add(calendar.day_of_month, 20); cal.add(calendar.hour, 19); cal.add(calendar.minute, 0); log.d("tag", cal.gettime().tostring());
why value?
d/tag﹕ thu jan 09 13:24:24 cest 4031
by using add
, getting calendar instance 2015 years, 6 months, 20 days, , 19 hours later now. instead use constructor:
calendar cal = new gregoriancalendar(2015, 5, 20, 19, 0);
and not call add
.
alternatively, can use set
instead of add:
cal.set(calendar.year, 2015); cal.set(calendar.month, 5); // 0-based cal.set(calendar.day_of_month, 20); cal.set(calendar.hour, 19); cal.set(calendar.minute, 0);
Comments
Post a Comment