Reputation: 936
I am Trying Parse Date string to Date but unable to parse . it showing some exceptions
Code
Date date = null;
String dtStart = "2013-11-08 05:46:55" ;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
try {
date = format.parse(dtStart);
System.out.println("Date ->"+date);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Stacktace:
11-08 19:04:06.394: W/System.err(8659): java.text.ParseException: Unparseable date: "2013-11-08 05:46:55"
11-08 19:04:06.402: W/System.err(8659): at java.text.DateFormat.parse(DateFormat.java:626)
Please give some solutions
Upvotes: 0
Views: 1089
Reputation: 4522
try this
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
date = format.parse(dtStart);
//Output it as a string that uses the new format
SimpleDateFormat newFormat_date= new SimpleDateFormat("dd MMMMMMMMM yyyy");
if (date!=null) {
String desiredDateFormat = newFormat_date.format(date);
holder.posted_on_date.setText(desiredDateFormat);
}else{
holder.posted_on_date.setText("N/A");
}
Upvotes: 1
Reputation: 14590
Change like this..you will get the date..
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Upvotes: 4