我在做一個android應用程序,我必須選擇特定的時間。在Android TimePicker對話框片段中顯示12hh格式
這是我到目前爲止已經完成:
public class TimePickerFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
// use the current time as the default values for the picker
Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
// create a new instance of TimePickerDialog and return it
return new TimePickerDialog(getActivity(), this, hour, minute, false
); // DateFormat.is24HourFormat(getActivity())
}
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute)
{
view.setIs24HourView(false);
String time;
if (minute < 10 ) {
_minute = ":0" + minute;
} else {
_minute = ":" + minute;
}
Log.w("TimePicker", "Time = " + time);
EditText activityButton = (EditText)getActivity().findViewById(R.id.etTime);
activityButton.setText(time);
}
我想實現的是:
6:30 PM
但我得到的是:
18:30
我想12H格式不是24小時。我怎樣才能做到這一點?非常感謝幫助。
http://www.compiletimeerror.com/2013/ 07 /時間選擇器功能於Android的example.html的#.Utd3-t_FsUQ。檢查這是否有幫助 – Raghunandan
謝謝你解決我的問題! – Dunkey
@Raghunandan該網址解決方案的問題是中午12:00 PM變成了12:00。 – Gordons