aspose file tools*
The moose likes Java in General and the fly likes Contradictions with Java Calendar API Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Contradictions with Java Calendar API" Watch "Contradictions with Java Calendar API" New topic
Author

Contradictions with Java Calendar API

dinesh laxman kumar
Greenhorn

Joined: Jul 11, 2012
Posts: 19
hi guys,

I have a small snippet wherein i am converting a String to Date ,
After which I set the date to a calendar and then



when i print the calendar object



I get the correct output

java.util.GregorianCalendar[time=1351103400000,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Asia/Calcutta",offset=19800000,dstSavings=0,
useDaylight=false,transitions=6,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2012,MONTH=9,WEEK_OF_YEAR=43,WEEK_OF_MONTH=4,
DAY_OF_MONTH=25,DAY_OF_YEAR=299,DAY_OF_WEEK=5,DAY_OF_WEEK_IN_MONTH=4,AM_PM=0,HOUR=0,HOUR_OF_DAY=0,
MINUTE=0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=19800000,DST_OFFSET=0]

when i print the day of the year separately like



The output is "6";

Help please,

Thanks in advance
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41808
    
  62
What you want is "cal.get(cal.DAY_OF_YEAR)" or something like that.


Ping & DNS - my free Android networking tools app
dinesh laxman kumar
Greenhorn

Joined: Jul 11, 2012
Posts: 19
Dittmer,

Many thanks, getting the right output,

By the way why that contradiction???
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

dinesh laxman kumar wrote:Dittmer,

Many thanks, getting the right output,

By the way why that contradiction???


It's not a contradiction. It was simply a case of you not reading the documentation closely enough, or not understanding it.

DAY_OF_YEAR (along with HOUR, MINUTE, etc.) is an int constant. In the case of DAY_OF_YEAR, the value is 6. It's always 6. When you call the get(int) method, the int tells it which field you want to get. So when you say get(DAY_OF_YEAR), you're saying get(field number 6).
dinesh laxman kumar
Greenhorn

Joined: Jul 11, 2012
Posts: 19
Oops, thanks for the input...

Thanks Jeff and Dittmer again,

Have a nice day...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Contradictions with Java Calendar API