我試圖以像下午7:45而不是19:45格式顯示當前時間,但我似乎無法找到正確的格式選項。標準時間與miltary時間
Time cTime= new Time(Time.getCurrentTimezone());
cTime.setToNow();
clock.setText(cTime.format("%H:%M"));
這似乎顯示軍事
我試圖以像下午7:45而不是19:45格式顯示當前時間,但我似乎無法找到正確的格式選項。標準時間與miltary時間
Time cTime= new Time(Time.getCurrentTimezone());
cTime.setToNow();
clock.setText(cTime.format("%H:%M"));
這似乎顯示軍事
您使用Time.format()
,所以你可以參考C++ strftime
documentation格式化規則。您的格式字符串應爲%I:%M%P
,時間爲12小時。
使用SimpleDateFormat
與a
- 意義AM/PM標記。
例子:
Calendar cal = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat("h:mmaa");
try {
String now = dateFormat.format(cal.getTime());
} catch (ParseException e) {
e.printStackTrace();
}
嘗試' 「%I:%M%P」' – Squonk