I am trying to parse a string to date, but the output look incorrect:
Below is my code.
public static void main(String[] args){
Date startDate = new Date();
DateFormat formatter = new SimpleDateFormat("dd.MM.yyyy hh:mm:ss");
try {
startDate = (Date) formatter.parse("07.10.2012 12:19:24");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Formatted Date " + startDate.toString());
}
Program Output:
Formatted Date Sun Oct 07 00:19:24 IST 2012
Expected Output:
Formatted Date Sun Oct 07 12:19:24 IST 2012
You might want to use 24h format instead of 12h format…
Yes, formatting characters are case sensitive.