Reputation: 78106
I have fields in a Mysql database typed datetime.
I store, for example, a payment's date with next Java code:
payment.setCreatedOn(new Date(System.currentTimeMillis()));
In my view layer I use fmt:formatDate to format dates:
<fmt:formatDate value="${payment.createdOn}" pattern="EEE, dd MMM yyyy HH:mm:ss"/>
My server is in London and my application's users are in Vienna. The time showing is delayed probably because of different time zones. I can use a timeZone Parameter in fmt:formatDate.
timeZone: Time zone in which to represent the formatted time.
After searching in Google, I think the value Europe/Vienna is valid for timeZone parameter.
Does anyone knows if there is list anywhere of the valid timeZone strings?
Upvotes: 0
Views: 4195
Reputation: 3610
You need to use the international time (UTC/Zulu) to add the following schedule client time use, for example "GMT+1". See this example.
Put this parameter as argument in your server to set UTC time use, in this case is for 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";
}
To show date choose your pattern you want (properties)
/* 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
Upvotes: 0
Reputation: 78155
Sergio - I'm sure you've long since found it anyway ...
Here's the homepage for the Olson database or 'zoneinfo' which is the definitive source of TZ info.
And here's a nice wiki for browsing zones.
Upvotes: 1