The constructor java.util.Date(int,int,int)
is deprecated. Is there a way to set a date easy as that in Java? What's the non-deprecated way to do this?
Date date = new Date(2015, 3, 2);
util. Date are deprecated since Java 1.1, the class itself (and java. util. Calendar , too) are not officially deprecated, just declared as de facto legacy.
Date Class. Many of the methods in java. util. Date have been deprecated in favor of other APIs that better support internationalization.
Joda-Time provides a quality replacement for the Java date and time classes. Joda-Time is the de facto standard date and time library for Java prior to Java SE 8.
The getTime() method of Java Date class returns the number of milliseconds since January 1, 1970, 00:00:00 GTM which is represented by Date object.
What's the non-deprecated way to do this?
Java 8 to the rescue:
LocalDate localDate = LocalDate.of(2015, 3, 2);
And then if you really really need a java.util.Date
, you can use the suggestions in this question.
For more info, check out the API or the tutorials for Java 8.
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