Question

I'm a little bit confused about using the class GregorianCalendar and Date.
What is the difference?

For instance: I have a field in a Person object that represents the date he was born. Do I have to use Date or GregorianCalendar?

What is the best use for them?

Was it helpful?

Solution

If you were writing down the details on paper, would you write down the date of birth as a date, or would you write down a calendar with a circle around the date?

You would write down the date. Date is a concrete date. Calendar is a tool for working with dates.

OTHER TIPS

I would use Date to represent the date of birth. Use Calendar (and child classes) to manipulate dates.

Both Date and Calendar classes suffer from poor APIs. You should use the Joda Time library instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top