Javascript Tip: Detect Client Time Zone
Many times we just need to gather visitor's time zone information. Below is a short script the result of which could be stored in a cookie or a hidden field. Function returns client GMT offset hours. The advantages of using client script are the following: you eliminate proxy location issues and daylight saving issues.
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); return hoursDiffStdTime; }
Enjoy :)
Wednesday, August 8, 2007 3:02 AM