Hi i am from India my timezone is Asia/Calcutta
and offset is +5.30
How to get dynamic timezone and offset?
Dynamic timezone means when an user access my website. This user can see his/her local time in my site.
If some one visit my website outside of India then how to display the local time? I have tried to find the timezone and offset but unable to get any satisfy answer. So i post here my question. Pleas help me and share your answer with example.
Thanks
ChatFun
You might use browser geolocation functionality:
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
... that will give you Lat and Lon which you might then use in a call to Google TimeZone API
https://maps.googleapis.com/maps/api/timezone/outputFormat?parameters
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.