I have a field called startDate with type TIMESTAMP I get from MySQL InnoDB database:
SELECT startDate FROM jn.all WHERE id IN(115)
=> 2012-07-28 00:00:00
In Java I do:
java.util.Date d = resultSet.getDate("startDate");
SimpleDateFormat tsmpFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
tsmpFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
System.out.println(tsmpFormatter.format(d));
I get:
=>2012-07-28 04:00:00
There are 4 hours from UTC to EST. Database time is UTC.
SELECT now();
=> 2013-07-29 21:46:26
While my current EST time is 17:46:26
Why am I getting this 4 hour difference even though I am using UTC everywhere? Thanks!
EDIT:
I may have found the issue.
http://dev.mysql.com/doc/refman/5.1/en/datetime.html
MySQL converts TIMESTAMP values from the current time zone to UTC for storage, and back from UTC to the current time zone for retrieval. (This does not occur for other types such as DATETIME.)
But what is this current time zone? Server should be in UTC.