I want to take a db date/time value in GMT and convert it to the local user's date/time. We have a lot of site users all over the world and I thought it would be helpful for them if it were easier to know when our online events were going to happen by seeing it in their own date/time. I've seen other pages that talk about doing this for forum systems, but those rely on cookies and I can't distill out just the info I need.
Currently I've got my js (below) set to read the user's system clock for the initial date/time, but eventually I'll pass in the value from the db. It determines the difference between their date/time and GMT, does the calculations to adjust the time difference, and then displays it.
Here's my test page if you want to see it in action.
I can't figure out if it will work when it's not Daylight Saving Time (DST), but I'm using ColdFusion and there's a function to determine DST so I could manipulate the value before I pass it into the Javascript. Time zones are always really hard for me to figure out.
Thanks,
Vilaine (Jessica)
<!--- need to send the database GMT date/time field into this --->
<script language="JavaScript">
myDate = new Date() //get the date/time from the user's machine
document.write('my system date/time is ' + myDate + '<BR>');
diff = myDate.getTimezoneOffset(); //get the difference between their date/time and GMT
document.write('the time difference in minutes ' + diff + '<BR>');
if ((navigator.appVersion.indexOf('MSIE 3') != -1)) diff = diff * (-1);
myDate.setTime(myDate.getTime() + diff*60*1000);
timezone = (diff/60);
myDate.setTime(myDate.getTime() + -timezone*60*60*1000);
document.write('my converted date/time is ' + myDate.toLocaleString());
</SCRIPT>
Currently I've got my js (below) set to read the user's system clock for the initial date/time, but eventually I'll pass in the value from the db. It determines the difference between their date/time and GMT, does the calculations to adjust the time difference, and then displays it.
Here's my test page if you want to see it in action.
I can't figure out if it will work when it's not Daylight Saving Time (DST), but I'm using ColdFusion and there's a function to determine DST so I could manipulate the value before I pass it into the Javascript. Time zones are always really hard for me to figure out.
Thanks,
Vilaine (Jessica)
<!--- need to send the database GMT date/time field into this --->
<script language="JavaScript">
myDate = new Date() //get the date/time from the user's machine
document.write('my system date/time is ' + myDate + '<BR>');
diff = myDate.getTimezoneOffset(); //get the difference between their date/time and GMT
document.write('the time difference in minutes ' + diff + '<BR>');
if ((navigator.appVersion.indexOf('MSIE 3') != -1)) diff = diff * (-1);
myDate.setTime(myDate.getTime() + diff*60*1000);
timezone = (diff/60);
myDate.setTime(myDate.getTime() + -timezone*60*60*1000);
document.write('my converted date/time is ' + myDate.toLocaleString());
</SCRIPT>