• 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

pull a year from a Calendar object

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a Calendar object called theStartDate. I want to know the year that is in it. I have to compare the year to another year. Looking in in the Java Docs online, I don't find what I need. Okay, it's there but I don't get it.

Thanks for the help.
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Given a Calendar object, there is a method get that accepts an int.

That int is a code for the information you want.

For convenience, there are compile-time constants like Calendar.YEAR that you can use to get the information.
 
Dorcas Rebanha
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ooh, ooh! Calendar.YEAR looks like what I want! Is that an int or a String?
 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is an int.

But Calendar.YEAR does not give you the year of the Calendar.

But if you send it to the get method, the method will return the year of the Calendar.
 
Dorcas Rebanha
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, this would give me the year as an int value, right?

int theYear = theStartDate.get(Calendar.YEAR);

Eclipse tells me the syntax is correct, but I just want to be sure that I am getting a value that I can use. My goal is to compare the year from theStartDate to another year.

I think you have given me what I need. Thank you verrrry much.
reply
    Bookmark Topic Watch Topic
  • New Topic