Results 1 to 3 of 3
  1. #1
    caibbor is offline Member
    Join Date
    Jun 2011
    Posts
    2
    Rep Power
    0

    Default Calendars in Java are completely unintuitive.

    I'm a C++ programmer, rewriting some programs in Java to port them to android. I've read whatever documentation I could find regarding the various Calendars in the Java standard library, but things just aren't working for me.

    in this snippet, I create a new calendar object and set it's year with two different methods, but neither actually work. the year that gets spat from println is always 1. what the heck is going on?

    Java Code:
    		GregorianCalendar cal = new GregorianCalendar();
    
    		cal.set(cal.YEAR, 1999);
    		System.out.println("> " + cal.YEAR);
    
    		cal.set(1999, 10, 10);
    		System.out.println("> " + cal.YEAR);

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    println is always 1
    What is the value of what you are printing: cal.YEAR?
    It looks like a static constant the way it is coded: All caps
    Read the Calendar class's API doc to see what it is defined as.

  3. #3
    caibbor is offline Member
    Join Date
    Jun 2011
    Posts
    2
    Rep Power
    0

    Default

    ah, so it is. here's the corrected code:

    Java Code:
    		cal.set(GregorianCalendar.YEAR, 1999);
    		System.out.println("> " + cal.get( GregorianCalendar.YEAR ) );
    
    		cal.set(1999, 10, 10);
    		System.out.println("> " + cal.get( GregorianCalendar.YEAR ) );
    reference: Calendar (Java 2 Platform SE 5.0)

Similar Threads

  1. Is JAVA completely object-oriented???
    By venkateshk in forum New To Java
    Replies: 2
    Last Post: 11-17-2008, 09:17 AM
  2. Completely new to Java problem
    By Seamo14 in forum New To Java
    Replies: 4
    Last Post: 10-09-2008, 12:50 PM
  3. Replies: 0
    Last Post: 07-13-2008, 01:47 PM
  4. How to store Multiple calendars in PIM Database
    By thirupathik in forum CDC and Personal Profile
    Replies: 0
    Last Post: 07-13-2008, 01:45 PM
  5. Calendars, what do you recommend to me?
    By tommy in forum New To Java
    Replies: 1
    Last Post: 07-27-2007, 10:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •