in JAVASCRIPT, is it possible to get country name that we selected in our system . for example if my system timezone is “india/kolkata” , we can get offset value like this :
d = new Date()
utc = d.getTime() + (d.getTimezoneOffset()*60000)
offset = (d.getTime()-utc)/3600000
thus offset is the required value like 5.5 for india .
But i donno getting the country name .
I thought of getting the country name by mapping the offset with the country name from my database of timezones . but i found that some countries have same timezones . for example, india and srilanka are two countries that have same timezones with offset 5.5 . So, how to get the correct country name in javascript from system’s timezone .
thanks
For client-side JavaScript, simple answer: you can’t. As you said, there can be (and generally is) multiple countries in the same timezone, with the exact same offset.
I don’t see any other reliable way to get the user country in pure JavaScript.
Why not simply ask your visitor?