File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply 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: 16
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: 35241
    
    7
What you want is "cal.get(cal.DAY_OF_YEAR)" or something like that.


Android appsImageJ pluginsJava web charts
dinesh laxman kumar
Greenhorn

Joined: Jul 11, 2012
Posts: 16
Dittmer,

Many thanks, getting the right output,

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

Joined: Jan 03, 2004
Posts: 5868
    
    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: 16
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
 
Similar Threads
how do i get day of the week from the date
Possble Calendar bug with daylight saving time
java.util.Calendar
setTime() function not setting the time
how to get the date from the string representation of date