I have some questions regarding timezones. We store all our date in UTC time, but we need to show some of them in local (US Eastern) time and UTC at the same time.
Here is my test, I have a date in UTC and want to display it in UTC and local time:
<html>
<!-- let's assume this date is in UTC, I get it from Database in my code -->
<jsp:useBean id="dateValue" class="java.util.Date" />
GMT
<fmt:formatDate value="${dateValue}" pattern="yyyy-MM-dd HH:mm:ss z" timeZone="GMT"/>
</html>
<!-- Displays the original time +4 - not what I need-->
No time zone
<fmt:formatDate value="${dateValue}" pattern="yyyy-MM-dd HH:mm:ss z"/>
<!-- Displays the original time, but timezone is EDT -->
US/Eastern
<fmt:formatDate value="${dateValue}" pattern="yyyy-MM-dd HH:mm:ss z" timeZone="US/Eastern"/>
<!-- Displays the original time, timezone is EDT, I need original + 4 -->
</html>
To reiterate: I have a UTC time from database and want to format it and show in UTC timezone. Server runs in other timezone than UTC.
Basically I need a function like
convertToTimezone(date, originalTimeZone, desiredTimeZone).
What fmt:formatDate provides is something like
convertToTimezone(date, serverTimeZone, desiredTimeZone).
I could hack it, but that usually causes problems when there is a daylight time saving, etc.
P.S. For those people looking for answers - one thing to do is to run your server in UTC, then the conversions would work fine. If can't change that, the only way to go is to create the new date with UTC time zone, do it explicitly, I myself converted the time I had to text, then created a new date and provided the data from the text and UTC timezone. If you don't do that, the timezone is read from the server.