I have an application that retrieves a string formatted in date time format from a database, and I want to display only the time in certain instances, how would I accomplish this?
This is what I have tried so far but I get an Unparsable error
public static final String DATE_TIME_FORMAT = "yyyy-MM-dd kk:mm:ss";
private static final String TIME_FORMAT = "kk:mm";
// ...
SimpleDateFormat TimeFormat = new SimpleDateFormat(TIME_FORMAT);
Date startTimer = null;
Date endTimer = null;
try
{
String dateString = cursor.getString(6);
startTimer = TimeFormat.parse(dateString);
//Code for End Time
String endDateString = cursor.getString(7);
endTimer = TimeFormat.parse(endDateString);
totalBillable += endTimer.getTime() - startTimer.getTime();
}
catch (ParseException e)
{
Log.e("ReminderEditActivity", e.getMessage(), e);
}
I’m guessing that you are getting
Unparsable errorbecause you are parsing a string date that has different format. Try this:Hopefully by this
substring()method, you will get thekk:mmdate format.