• 0

[Java]


Question

Hello everyone, currently I am trying to do my assignment for my Java class, however I stumbled upon a problem with using Date, because I get this: Date(java.lang.String) in java.util.Date has been deprecated

My assignment requires me use a certain date (Not the current date and time) and display it in "Fri Jan 01 00:00:00 PST 2010" format. However although

Date date = new Date ("Jan-01-2010");

does work, but it is deprecated, could someone show me how to use some other alternative? I tried looking at the Calender Class, and SimpleDate, etc.. but I have no idea after reading the docs how to do what I want to do.

Thanks!

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Date(java.util.String) was deprecated in JDK 1.1

Use DateFormatter instead:

public static Date parseDate(String date) {
    Date d = null;
    try {
        d = DateFormat.getInstance().parse(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return d;
}

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.