• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Contradictions with Java Calendar API

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What you want is "cal.get(cal.DAY_OF_YEAR)" or something like that.
 
dinesh laxman kumar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dittmer,

Many thanks, getting the right output,

By the way why that contradiction???
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oops, thanks for the input...

Thanks Jeff and Dittmer again,

Have a nice day...
 
reply
    Bookmark Topic Watch Topic
  • New Topic