Jon Nylander avatar Jon Nylander committed afa56b7

Comments (0)

Files changed (1)

 
 === Basic algorithm ===
 
-The first thing to find out is the user's offset from UTC time. This is done by first creating a date and converting it to UTC time.
-
-For the following example, imagine that your client is in Alaska.
+For the following example, imagine that your user has his computer's time set to Anchorage (Alaska).
 {{{
 #!javascript
 
 var ONE_HOUR_IN_MILLISECONDS = 3600000;
 
-// Creating a local date, midnight 1 January 2011
+// Create a local date, midnight 1 January 2011
 var january1 = new Date(2011, 0, 1, 0, 0, 0, 0); 
 
-// Converts local time to a UTC timestamp string
+// Convert local time to a UTC timestamp string
 // It looks like this: Sat, 01 Jan 2011 09:00:00 GMT
 var january1_gmt = january1.toGMTString();
 
 // with the string "Sat, 01 Jan 2011 09:00:00"
 january1_gmt = january1_gmt.substring(0, january1_gmt.lastIndexOf(" ")); 
 
-// We create a new date in local time based on the gmt time stamp
+// We create a new date in local time based on the gmt time stamp string
 var january2 = new Date(january1_gmt);
 
-// Comparing the two versions of the date we get the UTC offset.
-// (here divided by 3600000)
+// Comparing the two versions of the date we get the UTC offset.)
 var utc_offset = (january1 - january2) / (ONE_HOUR_IN_MILLISECONDS);
 
-console.log(offset); // # -9
+console.log(offset); // # The UTC offset is -9 hours
 }}} 
 
-Using a set of rather simple algorithms around the JavaScript Date object we can pinpoint nearly all timezones around the globe.
 
 === Who would benefit from this script? ===
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.