Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calendar returns incorrect values 1

Status
Not open for further replies.

Mellegem

Technical User
Apr 3, 2003
49
ZA
Hi all, a small section of my program is as follows

<code>
GregorianCalendar gc = new GregorianCalendar();
boolean less=false;

Calendar now = gc.getInstance();
int hr = now.get(Calendar.HOUR);
int dy=now.DAY_OF_MONTH;int dy2=now.DATE;
int min = now.MINUTE;
int ye=now.YEAR;int mo = now.MONTH;
System.out.println(now);
System.out.println(ye+&quot; YEAR &quot;+ mo+ &quot; MONTH &quot;+dy+&quot; DAY &quot;+min + &quot; MINUTE&quot;);
</code>

This code outputs

java.util.GregorianCalendar[...ERA=1,YEAR=2003,MONTH=8,
WEEK_OF_YEAR=38,WEEK_OF_MONTH=3,DAY_OF_MONTH=18,
DAY_OF_YEAR=261,DAY_OF_WEEK=5,DAY_OF_WEEK_IN_MONTH=3,
AM_PM=1,HOUR=7,HOUR_OF_DAY=19,MINUTE=46,...]

1 YEAR 2 MONTH 5 DAY 12 MINUTE

Any ideas why these bogus reading are being outputted? Last time I checked it isn't Year 1!
 
I think now.YEAR merely gives you the value of the constant YEAR.

What you want to do is:

int ye = now.get(Calendar.YEAR);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top