Coldfusion and TimeZones

Need a solution to work out a timezone issue. My server is in Japan, we have the program running for Japan Sites as well as the USA. The USA sites ae posting with the Japan dates and times…

Anyone have a solution for this?

I can’t mind the name bit check out riaforge. There is an open source download from there which will do it. Used it myself in my last project to force time to Australia when the server was in the US, but set to UK time :-D. I hate timezones, lol

Anyway from what I remember it uses Java to run it and was a fairly simple CFC.



I hate timezones

Add in DST and you’ve got a real fun-fest. You know whoever came up with that hair-brained idea was not a developer … :wink:

If your users log in and you know their locations, you could set up a table of timezones and then add/subtract the time from the server timezone.

If you don’t know the user’s location then you could also check the IP address and if the ip address is from the states then set a default time offset and calculate a time - everybody in the US would be on Central time for example.

I created this function for creating a time variable. datNow would be the server date and then I pass in the offsets. In this case, we do know where the users are and pass in the time difference from our server:

<cffunction name="myDateTime" displayName="myDateTime" hint="Returns a Local Time Based on User Timezone" access="public" returnType="date" output="false">
	<cfargument name="datNow" type="date" required="yes">
    <cfargument name="intTimeOffsetHours" type="numeric" required="yes">
	<cfargument name="intTimeOffsetMinutes" type="numeric" required="yes">
    <cfset myDateTime = DateAdd("h",#arguments.intTimeOffsetHours#,#arguments.datNow#)>
	<cfset myDateTime = DateAdd("n",#arguments.intTimeOffsetMinutes#,myDateTime)>
	<cfreturn myDateTime>