i got the error java.text.ParseException: Unparseable date
Use this it will work:
SimpleDateFormat formatter=new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy");
You cannot parse a date with a SimpleDateFormat that is set up with a different format
You should change your code to:
String v_date_str="Sun Mar 06 11:28:16 IST 2011";
DateFormat formatter;
formatter = new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy");
Date date_temp=null;
try {
date_temp = (Date) formatter.parse(v_date_str);
} catch (ParseException ex) {
Logger.getLogger(Attendance_Calculation.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println("output: "+date_temp);
You are using the wrong date format for parsing the date.
In this code you are telling Java to parse the date using the given format, and then print it. The format string you use must therefore match the format of the input date string. Since it doesn't, it's not surprising that it doesn't work.
To convert dates between two different formats you probably want to use two different DateFormat objects, one for the parsing and one for the printing.