lifegauge
asked on
My host has got his timezone set to something different from mine (i live somewhere across the globe from him).
My host has got his timezone set to something different from mine (i live somewhere across the globe from him).
Is there someway I can control the timezone via <cfml>, instead of having him change the time zone to suit mine?
Is there someway I can control the timezone via <cfml>, instead of having him change the time zone to suit mine?
ASKER
I'm thinking of setting request.mytime in application.cfm and refer to that instead of now() in my pages, but i'm not sure how to find out the difference. my timezone is gmt +8.
And what is their timezone?
GetTimeZoneInfo() will give you the time on the server and then you can use that with createDateTime to set a variable to match your local time so if the server time offset is 15hrs and you are offset 5 hours the diff is 10 hours so you could try
<cfset myVar=createDateTime(year( now()), month(now()), day(now()), hour(now())-10,minute(now( )),second( now()))>
but hour is supposed to be 0-23 so if yuo get a neg number you will need to do some more work to adjust the day then the month then the year
so
<cfset mysec=second(now())>
<cfset mymin=minute(now())>
<cfset myhour=hour(now())-10>
<cfif myhour lt 0>
<cfset myday=day(now())-1>
<cfset myhour=23+myHour>
</cfif>
<cfif myday lt 1>
<cfset mymonth=month(now())-1>
<cfset myday=1>
</cfif>
etc
<cfset mysec=second(now())>
<cfset myVar=createDateTime(year(
but hour is supposed to be 0-23 so if yuo get a neg number you will need to do some more work to adjust the day then the month then the year
so
<cfset mysec=second(now())>
<cfset mymin=minute(now())>
<cfset myhour=hour(now())-10>
<cfif myhour lt 0>
<cfset myday=day(now())-1>
<cfset myhour=23+myHour>
</cfif>
<cfif myday lt 1>
<cfset mymonth=month(now())-1>
<cfset myday=1>
</cfif>
etc
<cfset mysec=second(now())>
ASKER
This is kinda confusing, I've done it the short way before, just couldn't remember how to get it done therefore I believe there's any easier way to adjust the timezone, does anyone else have other suggestions?
Sure, try this:
<!--- get the time zone offset in hours from the server, I call it timez --->
<cfset timez = gettimezoneinfo()>
<!--- set the difference between your time and the server's time --->
<cfset timediff = -4>
<cfoutput>#dateadd("h", timez.utchouroffset+timedi ff, now())#</cfoutput>
<!--- get the time zone offset in hours from the server, I call it timez --->
<cfset timez = gettimezoneinfo()>
<!--- set the difference between your time and the server's time --->
<cfset timediff = -4>
<cfoutput>#dateadd("h", timez.utchouroffset+timedi
ASKER
Using this:
<!--- get the time zone offset in hours from the server, I call it timez --->
<cfset timez = gettimezoneinfo()>
<!--- set the difference between your time and the server's time --->
<cfset timediff = +8>
<cfset nowtime = #dateadd("h", timez.utchouroffset+timedi ff, now())#>
<cfoutput>
Current time: #dateformat(now(),'dd-mm-y yyy (HH:mm:ss)')#
<br>
New time: #dateformat(nowtime,'dd-mm -yyyy (HH:mm:ss)')#
</cfoutput>
I am getting this:
Current time: 07-05-2004 (09:05:13)
New time: 07-05-2004 (22:05:13)
The problem is, the current time (my time) is 22:50 and not 22:05.
How do I correct this problem?
<!--- get the time zone offset in hours from the server, I call it timez --->
<cfset timez = gettimezoneinfo()>
<!--- set the difference between your time and the server's time --->
<cfset timediff = +8>
<cfset nowtime = #dateadd("h", timez.utchouroffset+timedi
<cfoutput>
Current time: #dateformat(now(),'dd-mm-y
<br>
New time: #dateformat(nowtime,'dd-mm
</cfoutput>
I am getting this:
Current time: 07-05-2004 (09:05:13)
New time: 07-05-2004 (22:05:13)
The problem is, the current time (my time) is 22:50 and not 22:05.
How do I correct this problem?
So it isn't just a timezone issue then, but also a difference in the set times on the servers that you want to account for?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you know the difference however, you can just adjsut the time each time you display it.