I want to get the year/month/day values of a Date
object, but the docs say the getYear()
, etc. methods are deprecated. It suggests to use Calendar
instead, but I was wondering if it's okay to use the deprecated methods instead? It's just a toy program written in Processing, but I'll be doing quite a bit of Date operations on several objects, so speed might be a concern.

- 106,652
- 57
- 273
- 297

- 22,546
- 16
- 57
- 95
-
2In a toy program, use whatever you want. If you want to learn from your "toy", leave the deprecated methods behind – woliveirajr Jul 26 '11 at 11:30
-
Make use of the `java.util.Calendar` as suggested on this post. http://stackoverflow.com/questions/2654025/how-to-get-year-month-day-hours-minutes-seconds-and-milliseconds-of-the-curr – Bitmap Jul 26 '11 at 11:32
4 Answers
I would suggest you look at Yoda Time which is a much nicer library to work with for Date/Time tasks, in my opinion.

- 6,402
- 3
- 34
- 63
-
I would not recommend to depend on a third party library if you can achieve the thing you need with core Java very simple. – FrVaBe Jul 26 '11 at 12:43
Either one is fine. I would stick with Calendar
just to be consistent with the Java version. Deprecated methods should be avoided if only because it's a good habit to get into.
If there's a viable alternative, I would stay away from deprecated things unless you have a good reason to do so, such as speed. I doubt switching from Date
to Calendar
would cause a significant loss in speed. You may want to benchmark it just in case though.

- 35,812
- 14
- 73
- 140
If an API is deprected it might be dangerous or buggy. If suggested alternatives exist you should use them (and don't get used to ignore them). Using Calendar is not that hard to get what you need. If you have special calendar operations to do you can try Joda as mentioned by Charles Goodwin - but for your use case there seems to be no need to depend on a third party library.

- 47,963
- 16
- 124
- 157
I would not recommend using the Date methods. I see no advantage whatsoever. Calling that method on a Date
or Calendar
makes no difference to you as a programmer, does it? There's no benefit at all to calling it on a Date
instance.
As you've noted, these methods are deprecated. This means that they can be removed from the API without notice at any time. The reality is that it can only happen on a JVM upgrade. Your code will only stop working if you switch to a JVM that happens to have them removed.
So the risk is small that your code will suddenly stop working, but it's not zero.

- 305,152
- 44
- 369
- 561