Monday, August 5, 2013

My Javascript Function to Show UTC Time Zone of Your Browser/Computer

Your computer has its own time zone setting as well as the web host server. Most of the time they are quite different. United States alone has three different time zones.

It is crucial to get the time zone offset off the browser than the server as the time zone is something personal rather than a server sitting on a fixed location that tells nothing about the visitors possibly from the other side of the globe.

Here is a simple Javascript function to get the UTC time zone offset of your browser:

function getBrowserUTCTimezone() {
   x = new Date();
   return x.getTimezoneOffset()/-60;

Please note that the offset returned by the Javascript function getTimezoneOffset() will be divided by -60. Why negative? I'm not so sure. The invert of the number seems to give the right offset every time.

1 comment:

  1. Very informative and well written post! Quite interesting and nice topic chosen for the post.

    Samsung - 17.3" Notebook 8 GB Memory - 1 TB Hard Drive - Silver