0
我已經安裝了timePicker
爲24 hour
模式,但是如果時間目前16:05
我選擇16:10
從timePicker
,它說的12 hours and 5 minutes
代替5 minutes
。我如何輕鬆更換AM
和PM
?timePicker上午和下午交換並帶來了負面分鐘數
另外,如果我選擇相同的hour
而minutes
小於current minutes
,我會得到一個輸出,如12 hours and -4 minutes
。
代碼:
public void onClickAlarmOn(View v) {
final Calendar c = Calendar.getInstance();
TimePicker alarm_time_picker = (TimePicker) findViewById(R.id.timePicker); //initializing timePicker before using it //http://stackoverflow.com/questions/25485768/why-does-my-app-keep-crashing-when-i-try-to-insert-a-date-and-time-picker
int hour = alarm_time_picker.getCurrentHour(); //get selected hour
int minute = alarm_time_picker.getCurrentMinute(); //get selected minute
int hour_now = c.get(Calendar.HOUR); //get system's hour
int minute_now = c.get(Calendar.MINUTE); //get system's minute
int hour_result = hour - hour_now; //subtract the time selected by time.now of system
int minute_result = minute - minute_now;
String hour_result_string = String.valueOf(hour_result); //convert to string to display
String minute_result_string = String.valueOf(minute_result);
setToast_result("Alarm set to " + hour_result_string + " hours " + minute_result_string + " minutes");
}
謝謝!
是c#還是java?它不可能是兩個,可以嗎? – user1666620
@ user1666620對不起,困惑了一秒,修正了。 – hurkaperpa