Java - Parsing a Date from a String
- by Yatendra Goel
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