Displaying the Time in AM/PM format in android

private String getReminingTime() {
    String delegate = "hh:mm aaa";
    return (String) DateFormat.format(delegate,Calendar.getInstance().getTime());
}

I have done like this to achieve it.

private TimePickerDialog.OnTimeSetListener mTimeSetListener = new TimePickerDialog.OnTimeSetListener() {
    public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
        TextView datehid = (TextView)findViewById(R.id.timehidden);
        if(hourOfDay>12) {
            datehid.setText(String.valueOf(hourOfDay-12)+ ":"+(String.valueOf(minute)+"pm"));
        } else if(hourOfDay==12) {
            datehid.setText("12"+ ":"+(String.valueOf(minute)+"pm"));
        } else if(hourOfDay<12) {
            if(hourOfDay!=0) {
                datehid.setText(String.valueOf(hourOfDay) + ":" + (String.valueOf(minute) + "am"));
            } else {
                datehid.setText("12" + ":" + (String.valueOf(minute) + "am"));
            }
        }
    }
};    

Tags:

Android