Skip to content

Instantly share code, notes, and snippets.

@danswater
Last active August 29, 2015 14:09
Show Gist options
  • Save danswater/08cbecd8d071d359b22c to your computer and use it in GitHub Desktop.
Save danswater/08cbecd8d071d359b22c to your computer and use it in GitHub Desktop.
Timezone
<cfcomponent>
<cffunction name="conversion" returntype="any" access="remote" >
<cfargument name="localDate" type="string" required="true" >
<cfargument name="localTimeDiff" type="string" required="true">
<!--- assume the server is in utah --->
<cfset var utahTimeDiff = -7 >
<cfset var diff = utahTimeDiff + localTimeDiff >
<cfset var convertedDate = DateAdd( "h", diff, localDate ) >
<cfset var serverDate = dateFormat( convertedDate, 'd, mmm. yyyy' ) & " - " & timeFormat( convertedDate, 'hh:m:ss' ) >
<cfreturn serverDate >
</cffunction>
<cffunction name="main" returntype="any" access="remote" >
<cfset var localDate = Now() >
<cfset var localTimeDiff = GetTimeZoneInfo().utcHourOffset >
<cfoutput>Local time #dateFormat( localDate, 'd, mmm. yyyy' ) & " - " & timeFormat( localDate, 'hh:m:ss' )#</cfoutput><br />
<cfinvoke method="conversion" returntype="any" returnvariable="arrTimestamp" localDate = #localDate# localTimeDiff = #localTimeDiff# >
<cfoutput>Server time #arrTimestamp#</cfoutput>
</cffunction>
</cfcomponent>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment