I am trying to format endTime which is available in minutes / hours into AM/PM format. The problematic areas seems to be between 00.00 – 1.00 in the morning and 12.00 – 1.00 in the afternoon. Not sure if this is the right approach or is there a simpler way to accomplish this?
public final String getEndTime() {
StringBuffer buf = new StringBuffer();
buf.append(this.getEndTimeInHrs() < 13 ? this.getEndTimeInHrs() : this
.getEndTimeInHrs() - 13).append(COLON);
// this check is needed to prefix an additional string in front of the
// minute (e.g. for 6 hrs 5 minutes, it will be displayed as 6:05)
if (this.getEndTimeInMinutes() < 10) {
buf.append(0);
}
buf.append(this.getEndTimeInMinutes());
if (getEndTimeInHrs() < 12) {
buf.append(SPACE).append(AM);
} else if (getEndTimeInHrs() > 12) {
buf.append(SPACE).append(PM);
}
return buf.toString();
}
What about using a SimpleDateFormat with
h:mm a?E.g.: