I would have thought this code was impossible (cross domain security). Yet I found its basics on Stack Overflow and played with it to make something somewhat useful, and damned if it doesn't work:
Demo:Code:<!DOCTYPE html> <html> <head> <title>Current Time in lat/lng from lat/lng Using Google Maps API and jQuery</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> </head> <body> <div id="results"></div> <script type="text/javascript"> function curTimefrmLatLng(lat, lng){ var ts = Math.round(new Date().getTime() / 1000); var gmre = /[^\d]*$/; $.ajax({ url:"https://maps.googleapis.com/maps/api/timezone/json?location="+lat+","+lng+"×tamp="+ts.toString(10), success: function(response){ if(response.timeZoneId != null){ window.console && console.log(response); ts = ts + response.dstOffset + response.rawOffset; gm = new Date(ts * 1000).toUTCString().replace(gmre, " " + response.timeZoneName); $('#results').html('Current time in ' + response.timeZoneId + ' : ' + gm); } } }); } curTimefrmLatLng(34.0522, -118.2437); // running with LA's lat/lng </script> </body> </html>
http://jscheuer1.com/demos/tz.htm
Only impressive if you're not in the pst/pdt timezone.



Reply With Quote
Bookmarks