HOW TO show local time for a location based on its latitude and longitude


Here is a GitHub Gist snippet that shows how to get local time for a location based on its latitude and longitude using World Weather Online's Time Zone API & jQuery -
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
};
view raw gistfile1.js hosted with ❤ by GitHub

This can be useful in scenarios where you have to display time for a location relative to another.

Comments

Popular posts from this blog

The Mercurial Grok AI Assistant Understands & Speaks Indian Languages

Things Near Me – Find & Learn About Landmarks Nearby