Skip to content

Instantly share code, notes, and snippets.

@mvark
Last active December 16, 2015 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvark/5373959 to your computer and use it in GitHub Desktop.
Save mvark/5373959 to your computer and use it in GitHub Desktop.
JS snippet shows how to get local time for a location based on its latitude and longitude using World Weather Online's Time Zone API -http://www.worldweatheronline.com/time-zone-api.aspx
function time(lat, long) {
//replace the value for the key parameter with your own
var url = "http://api.worldweatheronline.com/free/v1/tz.ashx?q=" + lat + "," + long + "&format=json&key={key}&callback=tfunc";
//reference to jQuery library is required prior to using this function
$.getScript(url, function (response) { });
}
window.tfunc = function (response) {
var time = "";
time = "Local Time:" + response.data.time_zone[0].localtime;
$("#time").append(time); // #time represents a div whose id has the value time
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment