Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.util.Date(int,int,int) deprecated [duplicate]

Tags:

java

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);
like image 690
Stefan Falk Avatar asked May 27 '15 23:05

Stefan Falk


People also ask

Is Java Util calendar deprecated?

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.

Why date methods are deprecated in Java?

Date Class. Many of the methods in java. util. Date have been deprecated in favor of other APIs that better support internationalization.

What should I use instead of date Java?

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.

What does date () getTime () do in Java?

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.


1 Answers

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.

like image 133
Kevin Workman Avatar answered Oct 19 '22 00:10

Kevin Workman