作者:手机用户2602916235 | 来源:互联网 | 2023-06-15 09:30
Currentlythetimedisplayedas13:35PMHoweverIwanttodisplayas12hourformatwithAMPM,i.e
Currently the time displayed as 13:35 PM However I want to display as 12 hour format with AM/PM, i.e 1:35 PM instead of 13:35 PM
目前的时间显示为下午13:35,但我想显示为12小时格式的AM/PM,我。下午1点35分,而不是下午13:35。
The current code is as below
当前代码如下所示。
private static final int FOR_HOURS = 3600000;
private static final int FOR_MIN = 60000;
public String getTime(final Model model) {
SimpleDateFormat formatDate = new SimpleDateFormat("HH:mm a");
formatDate.setTimeZone(userContext.getUser().getTimeZone());
model.addAttribute("userCurrentTime", formatDate.format(new Date()));
final String offsetHours = String.format("%+03d:%02d", userContext.getUser().getTimeZone().getRawOffset()
/ FOR_HOURS, Math.abs(userContext.getUser().getTimeZone().getRawOffset() % FOR_HOURS / FOR_MIN));
model.addAttribute("offsetHours",
offsetHours + " " + userContext.getUser().getTimeZone().getDisplayName(Locale.ROOT));
return "systemclock";
}
13 个解决方案