Yesterday, I got into a problem with my work. On a Linux machine, I have a database (MySQL) table and there is a column in type time. I use the following java code to retrieve the value:
Time t = rs.getTime("columnName"); // rs is a ResultSet.
The Time objec is sent via HTTP to a GWT web application. The Time object is displayed correctly on a Firefox on linux (00:00:00) but not on a Firefox or IE on Windows (00:30:00).
No matter what value is in the database, the browsers on Windows will display it with an additional 30 mins.
My search starts with Java, JVM, tzdata. Test, trail and error for more than 1 day, finally, the error is the javascript engine. To understand the whole story, I must start with Java.
Base on the javadoc, java.sql.Time is actually a Date object. The date related fields should be set to 1970-Jan-01 and left untouced. Only the time part of it is (should be) used. When the value is read from database, a Time object is created. It is set to 1970-Jan-01 (Asia/Kuala Lumur). Base on the tzdata, the offset for “Asia/Kuala Lumpur” on 1970-Jan-01 is only +7:30 instead of +8:00. Thus, the Time object will have the value -27000000 (which means 00:00:00 +0:00 on 1970-Jan-01).
When this data is sent to the GWT application, the javascript engine in a Linux browser, correctly use the +7:30 offset. Thus, -27000000 plus +7:30 is 00:00:00. But on both Windows browsers, the offset used is +8:00. Thus, -27000000 plus +8:00 is 00:30:00.
To prove this: create a HTML file with the following content and open it with Firefox or epiphany on Linux, then do the same with IE or Firefox on Windows. Maybe another reason to use Linux instead of Windows:
<html>
<body>
<script type="text/javascript">
var d = new Date();
document.write("Current Date offset (min) = ");
document.write(d.getTimezoneOffset());
document.write("<br>");
d.setFullYear(1970,1,1);
document.write("1970-Jan-01 offset (min) = ");
document.write(d.getTimezoneOffset());
</script>
</body>
</html>