I am getting the time using a time picker and displaying the time in the text view using following code...
private TimePickerDialog.OnTimeSetListener mTimeSetListener = new TimePickerDialog.OnTimeSetListener() {
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
Toast.makeText(SendMail.this, "Your Appointment time is "+hourOfDay+":"+minute, Toast.LENGTH_SHORT).show();
TextView datehid = (TextView)findViewById(R.id.timehidden);
datehid.setText(String.valueOf(hourOfDay)+ ":"+(String.valueOf(minute)));
}
};
Now, the issue is when i set the time as 8:00 pm then i get the time displayed as 20:0... I want to display the time as 8:00 pm... How can i do that???
Pattern “hh:mm aa” and “HH:mm aa”, here HH is used for 24 hour format without AM/PM and the hh is used for 12 hour format with AM/PM. aa – AM/PM marker. In this example we are displaying current date and time with AM/PM marker.
To convert hh:mm:ss time format to minutes: =((HOUR(A2)*60)+MINUTE(A2)+(SECOND(A2)/60)); To convert hh:mm:ss time format to seconds: =HOUR(A2)*3600 + MINUTE(A2)*60 + SECOND(A2).
private String getReminingTime() {
String delegate = "hh:mm aaa";
return (String) DateFormat.format(delegate,Calendar.getInstance().getTime());
}
Calendar now = Calendar.getInstance();
if(now.get(Calendar.AM_PM) == Calendar.AM){
// AM
System.out.println(""+now.get(Calendar.HOUR)+":AM");
}else{
// PM
System.out.println(""+now.get(Calendar.HOUR)+":PM");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With