Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can You Determine Timezone from Request Variables?

Is there a way to do your timezone offsets on the server side, by reading something in the request over http, instead of sending everything to the client and letting it deal with it?

like image 916
DevelopingChris Avatar asked Dec 03 '08 19:12

DevelopingChris


People also ask

How do I know what timezone a user is in?

getTimezoneOffset()/60; The method getTimezoneOffset() will subtract your time from GMT and return the number of minutes. So if you live in GMT-8, it will return 480. To put this into hours, divide by 60.

How do I find the timezone of my server?

Checking Your Current TimezoneThe currently configured timezone is set in the /etc/timezone file. To view your current timezone you can cat the file's contents. Another method is to use the date command. By giving it the argument +%Z , you can output your system's current time zone name.

How do I get timezone from offset?

The JavaScript getTimezoneOffset() method is used to find the timezone offset. It returns the timezone difference in minutes, between the UTC and the current local time. If the returned value is positive, local timezone is behind the UTC and if it is negative, the local timezone if ahead of UTC.

How do I get current timezone in Servicenow?

gs. print("Value : " + gs. getProperty("glide.sys.default.tz")); It will show Empty TimeZone.


1 Answers

This is more complicated but I've had to resort to this scenario before because machine and user profile settings sometimes don't match your visitor's preferences. For example, a UK visitor accessing your site temporarily from an Australian server.

  1. Use a geolocation service (e.g MaxMind.com) as suggested by @balabaster, to get the zone matching their IP (Global.Session_Start is best). This is a good match for local ISPs, but not so good for AOL. Store the offset from this in a session cookie.

  2. Or use JavaScript to get the time zone offset as part of a form submission/redirect when the user enters the site. This is the browser's current offset, but not necessarily the visitor's preferred zone. Use this value as a default; store in another session cookie.

     <script type="text/javascript" language="JavaScript"> var offset = new Date(); document.write('<input type="hidden" id="clientTzOffset" name="clientTzOffset" value="' + offset.getTimezoneOffset() + '"/>'); </script> 
  3. Allow the visitor to update the zone via a persistent cookie (for anonymous users) and a field in their account profile (if authenticated).

The persistent value #3 from overrides the session values. You can also store the same persistent cookie for authenticated users for displaying times before they login.

like image 83
devstuff Avatar answered Sep 20 '22 20:09

devstuff