aspose file tools
The moose likes Beginning Java and the fly likes pull a year from a Calendar object 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 » Beginning Java
Reply Bookmark "pull a year from a Calendar object" Watch "pull a year from a Calendar object" New topic
Author

pull a year from a Calendar object

Dorcas Rebanha
Greenhorn

Joined: Apr 04, 2007
Posts: 18
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.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2341
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

Joined: Apr 04, 2007
Posts: 18
Ooh, ooh! Calendar.YEAR looks like what I want! Is that an int or a String?
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2341
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

Joined: Apr 04, 2007
Posts: 18
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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: pull a year from a Calendar object
 
Similar Threads
help understanding Calendar constructor vs method
turn string date to number date
Dispalying random dates
Date calculation
Tough Calendar class questions