I have problem with converting 24-hour format to 12 hour format. This is my code.
private TimePickerDialog.OnTimeSetListener mTimeSetListener =
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
// TODO Auto-generated method stub
ViewGroup vg=(ViewGroup) view.getChildAt(0);
hour = hourOfDay;
minutes = minute;
String am_pm = (hourOfDay < 12) ? "AM" : "PM";
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm a",Locale.US);
String tme = hour +":"+ minutes+am_pm;
et1.setText(tme);
}
};
I shift to timepicker dialog from alert dialog because i don't know how to change 24-hour to 12-hour format
et1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new TimePickerDialog(MainActivity.this, mTimeSetListener, hour, minutes, false).show();
}
});
}
This is the proof that i already turn the boolean impression to false.
Try this-