Last active
December 16, 2015 03:59
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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