Here is what is being stored in MYSQL {ts '2007-09-17 20:46:36'} Now This is three hours ahead as I live on the west coast and the server www.UNITEDLOCALBANDS.com lives on must be on the east coast. I have used all the different CF time and date format function but what I think that I have learnd is that none of them look at where the "client" viewing www.UNITEDLOCALBANDS.com is located. They are only looking at the server time. How can I retrieve the Local time for the "client" and not the server. When I return the date from the database I format it like this: #LSDateFormat("#DATE_TIME#", "mmm-dd-yyyy")#<br /> #LSTimeFormat("#DATE_TIME#", "hh:mm:sstt")# Code (markup): Thanks for your Help!
You're right. Those functions handle formatting not timezones. Timezones are _not_ my forte ;-) but here is an article that discusses the issue http://cfg11n.blogspot.com/2006/05/there-is-such-thing-as-timezone-hell.html
It pointed me in many great direction. I see there a few ways to make this work. I think I will have to use a little javascript to first determin the user Time Zone offset when they login. Then I can store it as a cookie and call on that cookie everytime I need to adjust the time. I'm trying to figure out now if it would be better to store the "GMT" or the "UTC" time in the database. I see both ways all over . Not sure exactly how to create either of these times. I saw one cfml script that shows the time zone of the server but it doesnt tell you the "GMT" offset. I havent got the getutc() function to work either. Basicaly I need to get some javascript to send back the client time zone to the server. Cfml will store a cookie while that user is logged in and also build some code to adjust the stored GMT timestamp to the clients GMT offset. Dont feel bad if your confused because I'm not sure if I understand what I just wrote. Oh well, Theres always tomarow. You've been a big help always and thanks for the article! James C
Here is part of what I need. Although I cant figure out how to make it work with coldfusion. I got it from a Mike H. on the Javascript forum. Very nice of him to whip this up. But I need to get it to work with coldfusion because he wrote it for php. I'm working on it though and once I get it to work I'll post back. <script type="text/javascript"> function xmitOffset(){ var refDate = new Date(); var gmtOffset = refDate.getTimezoneOffset() / 60; var AdminRequest = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); AdminRequest.open("GET", "save_user_offset.php?offset="+gmtOffset, true); AdminRequest.send(null); } onload=xmitOffset; </script> save_user_offset.php $userGMTOffset = $_GET['offset']; Code (markup):
Yeah, I'm still puzzling over the whole thing. I get the concept, but the DST issues are enough to make your head spin. Maybe we should create a petition recommending that DST be abolished ? ;-) If the user's are required to login, what about having them select their timezone when they sign up, and storing their offset from UTC (or your server time) in the database. When they login, read the value from the db and store it in a cookie/session variable and use that in your functions? Still thinking about potential pitfalls of that method. Did you check out the timeZone.cfc on that site? I think it has some of the functions you're looking for, so you don't have to reinvent the wheel http://www.sustainablegis.com/projects/tz/testTZCFC.cfm
Yeah, I looked through the timezone.cfc's and there are lots of great functions. The article is where I got this idea and its so simple. Thanks for your help with the "dateadd" function. Now that I can adjust the UTC I'm going to just add a little select menu to the registration page where they can select their time zone. And I'm going to store that info in the database. Then just dynamicaly return their timezone and correct all the times for all sorts of new stuff. This really is great. It's funny to me that one little function like dateadd and change so much about my website! James C
I have a simple login form with the the following javascript in the head section: <script language="javascript"> function getTimeZone(){ var rightNow = new Date(); var date1 = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0, 0); var temp = date1.toGMTString(); var date3 = new Date(temp.substring(0, temp.lastIndexOf(" ") -1)); var hoursDiffStdTime = (date1 - date3) / (1000 * 60 * 60); document.loginForm.ClientTZ.value = hoursDiffStdTime; document.loginForm.submit(); } </script> When the user clicks the submit button it does not submit the form directly, it has an "onclick" event: <cfinput id="submitForm" name="submitForm" onclick="getTimeZone()" type="submit" value="Click to Log In"> Note that type="button" will also work but the user would have to click the button. With type="submit", the onclick code runs first, then the form is submitted using either a click or a [return] key. This will get your client's offset in hours and send it with the form back to the server where you can take the form variable and store it in the session scope: <cfset Session.ClientTZ = Val(FORM.ClientTZ)>