I have a Java application that needs to be timezone aware. When I take the time of the Unix era and try to convert it to the timestamp used to call Oracle SQL, it gets the correct time zone, but the "useDaylightTime" value in the time zone is incorrect, i.e. It currently returns “true” when we are NOT in DST (I'm in Florida in the TZ “America / New York”).
This works on Red Hat Linux Enterprise 6, and as far as I can tell, it is correctly configured for the time zone, for example. Return 'date': Wed Nov 28 12:30:12 EST 2012
I also see, using the 'zdump' utility, that the current value for 'isdst' is 0.
My version of Java is 1.6.0_31.
I have googled this and have seen numerous problems that caused it, but many of them just say to install TZ manually, but my problem is not TZ, but the default TZ has "isDaylight" set to 'true '. I believe that this leads to the fact that my query returns data in one hour (I see that it is).
Here is a simple piece of code that I executed in order to try to reproduce it in the simplest way:
public class TZdefault { public static void main(String[] args) throws IOException { long startTime = System.currentTimeMillis()/1000; Calendar start = Calendar.getInstance(); start.setTimeInMillis(startTime); start.setTimeZone(TimeZone.getDefault()); System.out.println("Start UTC: " + start + "ms: " + start.getTimeInMillis()); System.out.println("use daylight: " + start.getTimeZone().useDaylightTime()); }
One last thing. If in my code I set TZ to "EST", it will of course return TZ with "isDaylight" set to False. But this is a bad decision.
I wanted to add a few details that I hoped to hide.
I have records in an Oracle 11g database that use TIMESTAMP with TIMEZONE fields. I just make JDBC queries where two parameters use a BETWEEN start timestamp and an end timestamp.
When I query this table, I use a prepared statement that uses a Calendar entry whose sole purpose was to try to manipulate the time zone. The bottom line is that I make a call to pstmt.setTimestamp () using the getTimeInMillis method to start and end the time when the default time zone was applied. Exiting the log shows that it actually puts the correct milliseconds, but the returned SQL results are clearly disabled for an hour for sure!
I'm still trying to verify that there is no problem on the data input side.
But I have a lot of debugging information, and it looks like I'm setting the right time in my JDBC request.