JAVA - Is it a bug in java.util.Calendar class or what?
android, calendar, date, java
Solution
It works perfectly as expected if you change to `getDate()` it outputs :
Time in mili of Current - Normal Wed Apr 04 11:34:34 BST 2012
Time in mili of Current - after update Fri May 04 11:34:34 BST 2012
What do you expect ? And in milleseconds it also equals 30 days :
Time in mili of Current - Normal 1333535834557
Time in mili of Current - after update 1336127834557
and the calculation is (difference, divided by milliseconds in a day) :
1336127834557 - 1333535834557 = 2 592 000 000
2592000000 / 86400000 = 30
And todays date in milliseconds after 1970 is 1333536754 ... which fits, I don't see a problem.
EDIT
Your Problem is you are setting Month like 3 for march...there you need to set 2..cause months are indexed from 0 to 11.
Problem
I have faced the same problem many times. The Same Problem was With This Question and Got Solution Like the Same, How to compare known hours ad current hour in android? Problem : When I use `Calendar calCurr = Calendar.getInstance();` to get the Calendar object of current date and time, It always return me wrong. I have put logs and checked it and to make it correct I had to add in years and months and then I got the correct object for Current Date and Time. See My Example : ``` Calendar calCurr = Calendar.getInstance(); Log.i("Time in mili of Current - Normal", ""+calCurr.getTimeInMillis()); // see what it gives? dont know why? Date date = new Date(); calCurr.set(date.getYear()+1900, date.getMonth()+1, date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds()); // so added one month to it Log.i("Time in mili of Current - after update", ""+calCurr.getTimeInMillis()); // now get correct ``` Question : - Why it's giving the wrong output? - Is it a bug in there or My concept about the Calendar class is wrong? - tell me what should have been done for that?