我手机上是下午5点30分。 (我的默认语言环境)
我在课堂上做了以下内容,但却得到了AM而不是PM。
public static class TimePickerFragment extends DialogFragment
{
private OnTimeSetListener listener;
public TimePickerFragment(OnTimeSetListener listener)
{
this.listener = listener;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
final Calendar c2 = Calendar.getInstance();
return new TimePickerDialog(getActivity(), listener, c2.get(Calendar.HOUR), c2.get(Calendar.MINUTE), false);
}
}
但是,这显示的是5.30 AM而不是PM。
怎么了?
答案 0 :(得分:0)
试试这段代码
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
final Calendar c2 = Calendar.getInstance();
return new TimePickerDialog(getActivity(), listener, c2.get(Calendar.HOUR), c2.get(Calendar.MINUTE), c2.get(Calendar.AM_PM));
}
对于AM
,c2.get(Calendar.AM_PM)的值= 0对于PM
,c2.get(Calendar.AM_PM)的值= 1