Java - Parsing a Date from a String

Posted by Yatendra Goel on Stack Overflow See other posts from Stack Overflow or by Yatendra Goel
Published on 2010-05-23T10:15:18Z Indexed on 2010/05/23 10:20 UTC
Read the original article Hit count: 305

Filed under:
|
|

I want to parse a java.util.Date from a String. I tried the following code but got unexpected output:

Date getDate() {
    Date date = null;

    SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd");
    try {
        date = sdf.parse("Sat May 11");
    } catch (ParseException ex) {
        Logger.getLogger(URLExtractor.class.getName()).log(Level.SEVERE, null, ex);
        return null;
    }

    return date;
}

When I run the above code, I got the following output:

Mon May 11 00:00:00 IST 1970

© Stack Overflow or respective owner

Related posts about java

Related posts about date