am_pm错误的im timepickerdialog

时间:2013-09-12 15:42:15

标签: android time timepicker android-timepicker

我手机上是下午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。

怎么了?

1 个答案:

答案 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