有什么办法只有国名,以获得时差? [英] Is there any way to get TimeZone by only country name?

查看:176
本文介绍了有什么办法只有国名,以获得时差?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我知道这个问题是问了很多次,但这些问题涉及web服务。我正在开发一个应用程序,显示时区由用户选择的国家。
比如我有所有的国家名单,并在用户从中选择一个国家想通过搜索国名时区(可以用字符串加拿大)。如果我搜索这样,才有可能从Android设备时区?注:我的应用程序不使用互联网连接。我想这些没有互联网连接。

Hi I know this question is asked many times but those question relate webservice. I am developing an app that shows timezone selecting country by user. For example I have list of all the countries and when a user select one country from them I want search TimeZOne by country name (May be by string "Canada"). If i search like this is it possible to get timezone from android device? Note: My application does not use internet connection. I want to these without internet connection.

除此之外,有没有相关的方式?

Apart from that is there any relevant way?

推荐答案

答案的国家到时区映射数据库地址大多数你的问题。

The Answers to Country to Timezone mapping database address most of your Question.

如果你想避免使用互联网,那么你应该能够嵌入数据库之一到你的Andr​​oid应用程序。但是,有您的Andr​​oid应用程序的旧版本可能有(逐渐)这一明显的问题外的日期时区信息。

If you want to avoid using the internet, then you should be able to embed one of the databases into your Android app. However, that has the obvious problem that old versions of your Android app could have (increasingly) out-of-date timezone information.

最后,你需要知道,一些国家有多个时区,所以不能确定的时区仅仅从国家名称。

Finally, you need to be aware that some countries have multiple timezones, so you cannot determine "the timezone" solely from a country name.

其他人使用时区 API和使用时区ID来找出国名建议。不幸的是,这并不正常工作 1 。在奥尔森数据库上的时区的ID的形式为区域/区,其中地区是美国,非洲等和位置通常是一个城市的名字。官方IDS不使用国名。

Others have suggested using the TimeZone API and using the timezone ids to figure out the country name. Unfortunately, this does not work1. The timezone ids on the "Olson" database are of the form "Area/Location", where the area is "America", "Africa", etc and the location is typically a city name. The official ids do not use country names.

维基百科参考: TZ数据库:区域名称

(显然, zone.tab 数据不包括国家codeS,不过我不认为这是在Java / Android的暴露时区 API)。

(Apparently, the zone.tab data does include country codes, but I don't think that is exposed in the Java / Android TimeZone API.)

1 - 除非该国是澳大利亚:-)

这篇关于有什么办法只有国名,以获得时差?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆