asha v
asha v

Reputation: 2109

How to get country name from time of android mobile?

Hi I am very new to Android Development. I want to pick the country name based on the current time of the particular mobile, while clicking the button. How can i do it? Any body tell me? Thanks in advance.

Upvotes: 0

Views: 3394

Answers (3)

Klas Lindbäck
Klas Lindbäck

Reputation: 33273

It seems difficult considering most timezones contain multiple countries (and countries multiple timezones as well).

See: Android: Is there a way to get timezone for Country name?

Upvotes: 3

Mathieu Dumoulin
Mathieu Dumoulin

Reputation: 12244

I don't think thats possible because you can have MANY MANY countries on the same time. For example, just take the GMT+/-0 time zone, you'll have England, France, Spain, Portugal, and a few others you can get from the african countries. You can't do it like that.

What i'd suggest is to implement a GEOIP location using for example: MaxMind GEOIP. You have some very powerful tools available in PEAR for that and it took me about 4 hours to setup the library, understand the code and do the code to query. I was querying for IPs and countries and even states/provinces in less than 4 hours. You can't get faster than that unless your a genious :)

Upvotes: 0

SW4
SW4

Reputation: 71190

Per above, the closest you'll get comes from here:

For getting the time zone, check out the "O" and "T" format specifiers of the date() function. "O" will give you the Difference to Greenwich time (GMT) in hours (your time zone offset) and "T" will give you the time zone abbreviation like "EST" for Eastern Standard Time.

e.g. <?php echo date("T"); ?> will give you the executing PHP script timezone, for the user timezome you can pass their date/time as the second argument.

Upvotes: 3

Related Questions