UTC Date Handling/Formatting/Converting - Point me in the right direction guys!

My app date/time stamps several pieces of data including audit and
error logs. I would prefer for each access account to be able to see
these date/time stamps in their local time zone instead of the time
zone the ColdFusion server exists in. It appears ColdFusion's
DateConvert("local2utc", curDate) will do a fantastic job converting
the current date/time to UTC, but my problem lies in converting it
back to local. Each access account has a time zone preference, so I
have the appropriate offsets all set.

I was told to look into the i18n plugin. Wow, talk about robust! Is
this the solution I'm looking for or is it complete overkill for my
needs? After browsing a few methods, I'm not 100% sure which I should
use. Can anyone help get me started here?

Will the i18n solve my date/time stamp fiasco? Or is it more geared
towards language localizations? I attempted to browse the API docs
but for some reason wasn't able to access them. Browsing the methods
raw left me flabbergasted as to all the methods it contained.

You can check TimezoneCFC.


Hmmm, maybe I'm over thinking this. Really, I just need to write a
method to take the UTC time and adjust it by the proper offset. The
dateAdd() function with an hour parameter passed in should handle this

locDate = dateAdd("h", "-5", currentUtcDate);

I suppose the only other work I'd need to do would be to check for DST
which shouldn't be too hard. If memory serves correct, there's a
built in coldfusion function along the lines of getTimeZoneInfo()

Sounds about right...

Hi Ryan,

Paul Hastings is the original author of this, and I am forwarding this to him as he is the i18n guru. Also oguz might jump in.

I have not done much in this area to comment intelligently. But I would just try the date/time methods.

Luis, I already provided the tool from Paul.

In the link there is a download which contains some CFC for all possible methods etc.

Here is the one that Ryan is looking for and he can find on the URL that I provided.

castfromUTC return date in given timezone from UTC datetime. required argument thisDate, optional argument thisTZ valid timezone ID, defaults to server timezone.

var tZ=variables.timeZone.getTimeZone(arguments.thisTZ); var tYear=javacast("int",Year(arguments.thisDate)); var tMonth=javacast("int",month(arguments.thisDate)-1); //java months are 0 based var tDay=javacast("int",Day(thisDate)); var tDOW=javacast("int",DayOfWeek(thisDate)); //day of week var thisOffset=tZ.getOffset(1,tYear,tMonth,tDay,tDOW,0)/1000; return dateAdd("s",thisOffset,arguments.thisDate);


Please try to check the solution on http://www.sustainablegis.com/projects/tz/testTZCFC.cfm link.


Oğuz Demirkapı


In my app I do exactly what you are trying to do using the TimezoneCFC referenced in this thread. There is a nifty method in there called castFromUTC. You pass in a date/time value and a valid timezone. The method returns the converted value adjusted for daylight savings (or not).

In my function I am setting ‘Timezone’ as a local var, and I’m converting the local now() value to UTC, then casting back to the timezone var. So, all you are passing in is a valid timezone, and you get the current date time back in that timezone. I am injecting TimezoneCFC in the instance scope. Here is how it looks…


Hope that helps.