0

我的手机上是下午 5.30。(我的默认语言环境)

我在课堂上做了以下事情,但得到的是上午而不是下午。

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。

怎么了 ?

4

1 回答 1

0

try this code

@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));
}

The value of c2.get(Calendar.AM_PM) = 0 for AM

The value of c2.get(Calendar.AM_PM) = 1 for PM

于 2013-09-12T16:04:05.113 回答