Results 1 to 3 of 3
- 06-29-2011, 10:13 PM #1
Member
- Join Date
- Jun 2011
- Posts
- 2
- Rep Power
- 0
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);
- 06-29-2011, 10:47 PM #2
What is the value of what you are printing: cal.YEAR?println is always 1
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.
- 06-29-2011, 11:42 PM #3
Member
- Join Date
- Jun 2011
- Posts
- 2
- Rep Power
- 0
ah, so it is. here's the corrected code:
reference: Calendar (Java 2 Platform SE 5.0)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 ) );
Similar Threads
-
Is JAVA completely object-oriented???
By venkateshk in forum New To JavaReplies: 2Last Post: 11-17-2008, 09:17 AM -
Completely new to Java problem
By Seamo14 in forum New To JavaReplies: 4Last Post: 10-09-2008, 12:50 PM -
How to store and access multiple calendars using a J2ME application
By thirupathik in forum CLDC and MIDPReplies: 0Last Post: 07-13-2008, 01:47 PM -
How to store Multiple calendars in PIM Database
By thirupathik in forum CDC and Personal ProfileReplies: 0Last Post: 07-13-2008, 01:45 PM -
Calendars, what do you recommend to me?
By tommy in forum New To JavaReplies: 1Last Post: 07-27-2007, 10:39 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks