actually it's not doing at all what it says it will. you are supposed to be able to set any one of the values specifically be it day date month year whatever. calendar.getinstance returns a calendar initialized to the current date and time. what i want to do is increment or decrement the month. so when i set Calendar.MONTH to a number, it should work. and in fact it does work for every case except february. so, nice try to make me look foolish, but you failed.
CaseyLOVESjava
@CaseyLOVESjava
Best posts made by CaseyLOVESjava
Latest posts made by CaseyLOVESjava
-
RE: Java calendar seems to be WTFing me
-
Java calendar seems to be WTFing me
ok so check this code snippet (the Calendar object in question is java.util.Calendar):
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH, 0);
System.out.println("WTF= " + cal.get(Calendar.MONTH));Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH, 1);
System.out.println("WTF= " + cal.get(Calendar.MONTH));Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH, 2);
System.out.println("WTF= " + cal.get(Calendar.MONTH));Program Output:
WTF= 0
WTF= 2
WTF= 2... i'm telling the calendar to set itself to 0 (january) then verify that it is on january, then february and verify etc.
however when i set the calendar to 1 (february) the get method returns 2 (march), so this calendar can never be set to february, or at least it can never show me that it has been set to february.
I really hope i'm making the mistake here, but i've tested it a lot and i'm pretty sure that it is a WTF on the part of Sun's programmers.
So my question is this, if the error is mine, how do i fix it? or if you also say WTF, how do i submit this as a dailyWTF?