Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
357 views
in Technique[技术] by (71.8m points)

android - How do I set AM/PM in a TimePicker?

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));
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...