我試過這int newHoursValue =(now.get(Calendar.HOUR_OF_DAY); int newMintsValue = (now.get(Calendar.MINUTE);
如何在android studio中分別獲取小時和分鐘?
但我沒有得到實際的時間在幾分鐘內不匹配,它不能在24小時制。我想得到一個在24小時和12小時格式兼容的人。請幫忙。
我試過這int newHoursValue =(now.get(Calendar.HOUR_OF_DAY); int newMintsValue = (now.get(Calendar.MINUTE);
如何在android studio中分別獲取小時和分鐘?
但我沒有得到實際的時間在幾分鐘內不匹配,它不能在24小時制。我想得到一個在24小時和12小時格式兼容的人。請幫忙。
HOUR_OF_DAY將返回小時,前導零,對於分鐘您可以使用
String curTime = String.format("%02d:%02d", hrs, mnts);
或
SimpleDateFormat df = new SimpleDateFormat("hh:mm");
//執行此操作。 。 。 日期currentDate = new Date();
/*for 24 hours format*/
SimpleDateFormat simpleDate1 = new SimpleDateFormat("HH");
String hours24 = simpleDate1.format(currentDate);
/*for 12 hours format*/
SimpleDateFormat simpleDate2 = new SimpleDateFormat("hh");
String hours12 = simpleDate2.format(currentDate);
/*for minutes*/
SimpleDateFormat simpleDate3 = new SimpleDateFormat("mm");
String minutes = simpleDate3.format(currentDate);
重複? https://stackoverflow.com/q/22525961/2655092 – IddoE