javadate

Java util.Date usage


I wanted to use the util.Date class in Java, but when I tried to instantiate a Date object, I realized that all the constructors that I can understand--the simple ones--were gone. All deprecated.

Can anybody tell me how I can make use of Date class?

Here is my code.

Constructor:

public Company(int id, String name, Date foundationDate) {
    super();
    this.id = id;
    this.name = name;
    this.foundationDate = foundationDate;
}

TestClass:

Company[] companies = new Company[3];
companies[0] = new Company(1, "Sabanci", new Date(12,12,12));

Solution

  • This constructor has been deprecated since Java 1.1 (a long time ago) From the javadoc

    Date(int year, int month, int date)

    Deprecated.

    As of JDK version 1.1, replaced by Calendar.set(year + 1900, month, date) or GregorianCalendar(year + 1900, month, date).

    As for the vastly superior JODA Time approach (from JavaDoc):

    new DateTime(2012,12,12,0,0);