Wednesday, November 17, 2010

Railo - Java Timezone Issue

I reset the system time zone in Ubuntu and then restarted Railo, but railo didn't have the new timezone.

I didn't want to reboot the server, so I researched and scripted this work-around:

<cfset variables.tzobj = CreateObject("java", "java.util.TimeZone") />

<cfset loc.timeZone = variables.tzobj.getDefault()>
Before Reset: <cfoutput>#loc.timeZone#</cfoutput><br /><br />

<cfset variables.tzobj.setDefault("US/Pacific")>

<cfset loc.timeZone = variables.tzobj.getDefault()>
After Reset:<cfoutput>#loc.timeZone#</cfoutput>

I ran that one on the server and it's good to go forever. I'll reboot the server late tonight and confirm that java gets the correct system timezone, but this worked for an immediate solution without rebooting or restarting Railo.

UPDATE: The above resolved the java offset, but issues were discovered between Railo (java) and SQL Database dates. It was converting back and forth between UTC and PDT (Pacific Daylight Savings Time). It was a mess. In addition, upon reboot Java revered back to the incorrect timezone. I had to test a fresh reboot because it was bound to happen. Glad I did.

The final solution to fixing the Java incorrect timezone came from a forum thread which pointed me to this link:

From there I leaned that there is another timezone file in Ubuntu located /etc/timezone which has Etc/UTC inside. That's it.

Simply deleting the file, or renaming it to /etc/timezone_old, and then rebooting fixed the java timezone.

The Java timezone object above is not a good solution. As I stated, there remains timezone issues between Railo CFML (essentially the Java Engine) and any other systems, namely MySQL.

Many thanks to the communities and forums for posting solutions.