您需要使用国际时间(UTC/Zulu)添加以下调度客户端时间使用,例如“GMT+1”。请参阅此示例。
将此参数作为参数放在您的服务器中以设置 UTC 时间使用,在这种情况下适用于 tomcat:
-Duser.timezone="UTC"
/* Java */
@RequestMapping(value = "/web", method = { RequestMethod.POST, RequestMethod.GET })
public String web(Model model, HttpSession session, Locale locale) {
Date today = new Date();
model.addAttribute("currentTime", today);
model.addAttribute("timezone", "GMT+1");
return "web";
}
要显示日期,请选择您想要的模式(属性)
/* JSP web */
<fmt:timeZone value="${timezone}">
<spring:message code="date_format_dateMin" var="pattern"/>
<fmt:formatDate value="${currentTime}" timeZone="${timezone}" pattern="${pattern}" var="searchFormated" />
<span class="innerLabel">${searchFormated}</span>
</fmt:timeZone>
/* Properties */
date_format_dateMin=yyyy/MM/dd HH:mm
date_format=yyyy/MM/dd HH:mm:ss
date_format2=yyyy/MM/dd
date_format3_js=yy/mm/dd
date_format4_time=HH:mm
date_format4=dd/MM/yyyy HH:mm:ss