Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

problems with Calendar

807606Mar 14 2007 — edited Mar 14 2007
I have noticed some calendar anomalies.
If I run the following code:
import java.util.GregorianCalendar;
import java.util.Date;
import java.util.Calendar;

public class TimeTest {
      public static void main (String[] args) {
            GregorianCalendar cal = new GregorianCalendar();
            Calendar cal2 = Calendar.getInstance();
            Date now = new Date();
            cal.setTime(now);
		
            System.out.println ("Month = " + cal.get(cal.MONTH) + ", " + cal2.get(cal2.MONTH));
            System.out.println ("Hour = " + cal.get(cal.HOUR) + ", HOUR_OF_DAY = " + cal.get(cal.HOUR_OF_DAY));
		
      }
}
I get an output of 2 for the month, and one hour later than the current time for the hour. Does anyone know what could be causing this?

Many thanks,

-Stile

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Apr 11 2007
Added on Mar 14 2007
2 comments
83 views