What can I use to replace this, new Date(2009, 12, 9)
?
Thanks for your help.
The standard alternate is using the Calendar Object. Calendar has one dangerous point (for the unwary) and that is the after / before methods. They take an Object but will only handle Calendar Objects correctly. Be sure to read the Javadoc for these methods closely before using them.
Date Class. Many of the methods in java. util. Date have been deprecated in favor of other APIs that better support internationalization.
deprecated means the usage of this constructor is discouraged, and it may be removed in future releases of Java.
The java. util. Date. after() method is used to check whether the current instance of the date is after the specified date.
Note: this answer was written in 2009. Since then, java.time
has become the preferred date/time API in Java.
Ideally, use Joda Time instead. It's an infinitely superior API to the built-in one. You'd then want to choose between LocalDateTime
and DateTime
depending on your exact requirements (it's a complicated area - I'm not going to try to summarise in a sentence or two, but the docs do a good job).
If absolutely necessary, use a java.util.Calendar and convert that to a Date
when you need to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With