如何在TimePicker中设置AM/PM? [英] How do I set AM/PM in a TimePicker?

查看:390
本文介绍了如何在TimePicker中设置AM/PM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用中使用了TimePicker.每当用户使用TimePicker打开屏幕时,我都会使用当前时间对其进行初始化.当我这样做时,TimePicker显示AM而不是PM.为什么会这样?我必须在代码中添加任何内容吗?

I am using a TimePicker in my app. Whenever the user opens the screen with the TimePicker, I initialize it with the current time. When I do this, the TimePicker shows AM instead of PM. Why does this happen? Is there anything I have to add in my code?

Date initDate = m_NoteManageObject.getDateTimeArray(position);
Calendar myCal = Calendar.getInstance();

myCal.setTime(initDate);
TimePicker timePicker  = (TimePicker)layout.findViewById(R.id.time_picker);

// Initialise Time Picker

timePicker.setCurrentHour(myCal.get(Calendar.HOUR));
timePicker.setCurrentMinute(myCal.get(Calendar.MINUTE));

推荐答案

您将不得不使用Calendar.HOUR_OF_DAY而不是Calendar.HOUR.

You'll have to use Calendar.HOUR_OF_DAY instead of Calendar.HOUR.

timePicker.setCurrentHour()始终期望参数为24小时格式.不幸的是,API文档中没有正确记录此事实.

i.e., timePicker.setCurrentHour() always expects the argument in 24-hour format. Unfortunately, this fact is not documented properly in the API documentation.

这篇关于如何在TimePicker中设置AM/PM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆