How to format hours, minutes in AM/PM format
<p>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?</p>

<pre><code>public final String getEndTime() {
    StringBuffer buf = new StringBuffer();
    buf.append(this.getEndTimeInHrs() &lt; 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() &lt; 10) {
        buf.append(0);
    }
    buf.append(this.getEndTimeInMinutes());

    if (getEndTimeInHrs() &lt; 12) {
        buf.append(SPACE).append(AM);
    } else if (getEndTimeInHrs() &gt; 12) {
        buf.append(SPACE).append(PM);
    }

    return buf.toString();
}
</code></pre>
