<i id='RjRAR'><tr id='RjRAR'><dt id='RjRAR'><q id='RjRAR'><span id='RjRAR'><b id='RjRAR'><form id='RjRAR'><ins id='RjRAR'></ins><ul id='RjRAR'></ul><sub id='RjRAR'></sub></form><legend id='RjRAR'></legend><bdo id='RjRAR'><pre id='RjRAR'><center id='RjRAR'></center></pre></bdo></b><th id='RjRAR'></th></span></q></dt></tr></i><div id='RjRAR'><tfoot id='RjRAR'></tfoot><dl id='RjRAR'><fieldset id='RjRAR'></fieldset></dl></div>
    1. <small id='RjRAR'></small><noframes id='RjRAR'>

        <bdo id='RjRAR'></bdo><ul id='RjRAR'></ul>
      <legend id='RjRAR'><style id='RjRAR'><dir id='RjRAR'><q id='RjRAR'></q></dir></style></legend>

      1. <tfoot id='RjRAR'></tfoot>
      2. 有没有办法使用(仅)国家代码(有效的 ISO-3166 代码)获得时区?

        时间:2023-09-25
          <tbody id='en5vq'></tbody>

        • <legend id='en5vq'><style id='en5vq'><dir id='en5vq'><q id='en5vq'></q></dir></style></legend>
          • <bdo id='en5vq'></bdo><ul id='en5vq'></ul>

            <tfoot id='en5vq'></tfoot>

              1. <small id='en5vq'></small><noframes id='en5vq'>

                <i id='en5vq'><tr id='en5vq'><dt id='en5vq'><q id='en5vq'><span id='en5vq'><b id='en5vq'><form id='en5vq'><ins id='en5vq'></ins><ul id='en5vq'></ul><sub id='en5vq'></sub></form><legend id='en5vq'></legend><bdo id='en5vq'><pre id='en5vq'><center id='en5vq'></center></pre></bdo></b><th id='en5vq'></th></span></q></dt></tr></i><div id='en5vq'><tfoot id='en5vq'></tfoot><dl id='en5vq'><fieldset id='en5vq'></fieldset></dl></div>
                  本文介绍了有没有办法使用(仅)国家代码(有效的 ISO-3166 代码)获得时区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试为用户获取 TimeZone.

                  I'm trying to get a TimeZone for a user.

                  为此,我有一个国家代码,它是一个有效的 ISO 国家代码.这些代码是 ISO-3166 定义的大写的两个字母代码.您可以在许多网站上找到这些代码的完整列表,例如:http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html

                  For this I have a country code which is a valid ISO Country Code. These codes are the upper-case, two-letter codes as defined by ISO-3166. You can find a full list of these codes at a number of sites, such as: http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html

                  我认为答案是不,因为它是多对多关系......像美国这样的国家可能有很多时区......".这就是问题所在……

                  I think the response is "no because it's a manytomany relationship... there can be many timezone for a country like USA ...". That's the problem...

                  我尝试过类似的东西:

                  //CountryEnum contains ISO_3166 values (http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html) 
                    //List all country to test timezone:
                    for (int i = 0; i < CountryEnum.values().length; i++) {
                     String isoCountryCode = CountryEnum.values()[i].name();// Get the iso country code
                     Locale locale = new Locale(isoCountryCode);// Build a country specific locale
                     Calendar calendar = Calendar.getInstance(locale);// Build a calendar with the specific locale
                     String timeZone = calendar.getTimeZone().getDisplayName();// Build a timeZone with the calendar
                     System.out.println("LOCALE : "+locale+" / COUNTRY: "+isoCountryCode+" / TIMEZONE: "+timeZone);
                    }
                  

                  但它总是返回服务器 TimeZone ...

                  But it always return server TimeZone ...

                  有什么想法吗?

                  推荐答案

                  Locale 不是 TimeZone,反之亦然.检查 Javadoc 用于您正在使用的方法 - 第一行说

                  A Locale is not a TimeZone, and vice versa. Check the Javadoc for the method you're using - the very first line says

                  获取使用默认时区和指定区域设置的日历.

                  Gets a calendar using the default time zone and specified locale.

                  这就是您获得默认时区的原因 - 因为您在获取日历时没有指定时区.

                  That's why you're getting the default timezone - since you didn't specify one when obtaining a Calendar.

                  想想 Jon 所说的 - 如果您知道在确定用户来自美国的情况下想要使用哪个时区,那么您可以调用 Calendar.getInstance采用时区语言环境的方法.另一方面,如果你不能明确地说你会在这里做什么,那就回到绘图板上,多考虑一下你的需求,而不是看你的实现.

                  Think about what Jon said - if you know what timezone you would want to use in the situation where you've worked out a user is from the US, then you can call the Calendar.getInstance method that takes a timezone and a locale. On the other hand, if you can't say definitely what you would do here, then go back to the drawing board and think about your requirements a little more, rather than looking at your implementation.

                  如果你不能回答上一个问题,我认为大多数网站的标准追索权是允许用户指定他们的首选时区(如果他们在服务器上有一个永久帐户),如果他们默认他们为服务器的时区没有说别的.如果他们没有永久帐户,并且他们正在向您提供时间信息(例如 XML 上传),那么他们将必须指定他们在请求中使用的时区,或者(可能更好)您要求始终使用 UTC.

                  If you can't answer the previous question, I think the standard recourse of most websites is to allow users to specify their preferred timezone (if they have a persistent account on the server) and default them to the server's timezone if they haven't said otherwise. If they don't have persistent accounts, and they're supplying information to you with times in (e.g. an XML upload), then they will have to either specify what time zone they're using in the request, or (probably better) you mandate the use of UTC for all times.

                  这篇关于有没有办法使用(仅)国家代码(有效的 ISO-3166 代码)获得时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:java中的日期时区转换? 下一篇:java Timezone setDefault 效果

                  相关文章

                1. <legend id='UOeJW'><style id='UOeJW'><dir id='UOeJW'><q id='UOeJW'></q></dir></style></legend>
                2. <tfoot id='UOeJW'></tfoot>
                    <bdo id='UOeJW'></bdo><ul id='UOeJW'></ul>

                  <small id='UOeJW'></small><noframes id='UOeJW'>

                3. <i id='UOeJW'><tr id='UOeJW'><dt id='UOeJW'><q id='UOeJW'><span id='UOeJW'><b id='UOeJW'><form id='UOeJW'><ins id='UOeJW'></ins><ul id='UOeJW'></ul><sub id='UOeJW'></sub></form><legend id='UOeJW'></legend><bdo id='UOeJW'><pre id='UOeJW'><center id='UOeJW'></center></pre></bdo></b><th id='UOeJW'></th></span></q></dt></tr></i><div id='UOeJW'><tfoot id='UOeJW'></tfoot><dl id='UOeJW'><fieldset id='UOeJW'></fieldset></dl></div>