我试图以晚上 7:45 而不是 19:45 的格式显示当前时间,但我似乎找不到正确的格式选项。
Time cTime= new Time(Time.getCurrentTimezone());
cTime.setToNow();
clock.setText(cTime.format("%H:%M"));
这似乎显示了军事
我试图以晚上 7:45 而不是 19:45 的格式显示当前时间,但我似乎找不到正确的格式选项。
Time cTime= new Time(Time.getCurrentTimezone());
cTime.setToNow();
clock.setText(cTime.format("%H:%M"));
这似乎显示了军事
SimpleDateFormat
与- 一起使用,a
表示上午/下午标记。
例子:
Calendar cal = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat("h:mmaa");
try {
String now = dateFormat.format(cal.getTime());
} catch (ParseException e) {
e.printStackTrace();
}
您正在使用Time.format()
,因此您可以参考C++strftime
文档以了解格式化规则。您的格式字符串应%I:%M%P
为 12 小时时间。