[android-developers] Re: How do you get the local time zone?

2009-02-21 Thread bw

Issue resolved here:

http://code.google.com/p/android/issues/detail?id=2037



On Feb 19, 2:12 am, bw ben.weisb...@gmail.com wrote:
 I found a pseudo-workaround that uses getResources().getConfiguration
 ().locale.getCountry() and looks up timezone by country code. For any
 country that contains more than 1 time zone, this will only calculate
 time for one of those timezones. Also, this doesn't handle daylight
 savings vs. standard time.

 -Ben

 Ps. Here's the code:

         MapString, Integer timeZoneOffsetMap = new HashMapString, Integer
 ();
         {
                 timeZoneOffsetMap.put(CZ,+1);  // Czech Republic
                 timeZoneOffsetMap.put(AT,+1);  // Austria
                 timeZoneOffsetMap.put(BE,+1);  // Belgium
                 timeZoneOffsetMap.put(CH,+1);  // Switzerland
                 timeZoneOffsetMap.put(DE,+1);  // Germany
                 timeZoneOffsetMap.put(LI,+1);  // Liechtenstein
                 timeZoneOffsetMap.put(LU,+1);  // Luxembourg
                 timeZoneOffsetMap.put(AU,+11); // Australia
                 timeZoneOffsetMap.put(BE,+1);  // Belgium
                 timeZoneOffsetMap.put(BW,+2);  // Botswana
                 timeZoneOffsetMap.put(BZ,-6);  // Belize
                 timeZoneOffsetMap.put(CA,-6);  // Canada
                 timeZoneOffsetMap.put(GB,+0);  // United Kingdom
                 timeZoneOffsetMap.put(HK,+8);  // Hong Kong SAR China
                 timeZoneOffsetMap.put(IE,+0);  // Ireland
                 timeZoneOffsetMap.put(IN,+6);  // India
                 timeZoneOffsetMap.put(JM,-5);  // Jamaica
                 timeZoneOffsetMap.put(MH,+12); // Marshall Islands
                 timeZoneOffsetMap.put(MT,+1);  // Malta
                 timeZoneOffsetMap.put(NA,+1);  // Namibia
                 timeZoneOffsetMap.put(NZ,+13); // New Zealand
                 timeZoneOffsetMap.put(PH,+8);  // Philippines
                 timeZoneOffsetMap.put(PK,+5);  // Pakistan
                 timeZoneOffsetMap.put(SG,+8);  // Singapore
                 timeZoneOffsetMap.put(TT,-4);  // Trinidad and Tobago
                 timeZoneOffsetMap.put(US,-6);  // United States
                 timeZoneOffsetMap.put(VI,-4);  // U.S. Virgin Islands
                 timeZoneOffsetMap.put(ZA,+2);  // South Africa
                 timeZoneOffsetMap.put(FR,+1);  // France
                 timeZoneOffsetMap.put(BE,+1);  // Belgium
                 timeZoneOffsetMap.put(NL,+1);  // Netherlands
         }

 String country = context.getResources().getConfiguration
 ().locale.getCountry().toUpperCase();
 int timeZoneOffset_hours = 0;
 if(timeZoneOffsetMap.containsKey(country)) {
         timeZoneOffset_hours= timeZoneOffsetMap.get(country);

 }

 int timeZoneOffset_millisec = timeZoneOffset_hours * 60 * 60 * 1000
 long now = System.currentTimeMillis() + timeZoneOffset_millisec;

 On Feb 18, 10:12 pm, bw ben.weisb...@gmail.com wrote:

  Hi,

  I can't figure out how to get the local time zone...

  TimeZone.getDefault() returns Pacific Time, while my phone's settings
  show the time zone correctly set to EST.

  Thanks
  -Ben
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: How do you get the local time zone?

2009-02-18 Thread bw

I found a pseudo-workaround that uses getResources().getConfiguration
().locale.getCountry() and looks up timezone by country code. For any
country that contains more than 1 time zone, this will only calculate
time for one of those timezones. Also, this doesn't handle daylight
savings vs. standard time.

-Ben

Ps. Here's the code:


MapString, Integer timeZoneOffsetMap = new HashMapString, Integer
();
{
timeZoneOffsetMap.put(CZ,+1);  // Czech Republic
timeZoneOffsetMap.put(AT,+1);  // Austria
timeZoneOffsetMap.put(BE,+1);  // Belgium
timeZoneOffsetMap.put(CH,+1);  // Switzerland
timeZoneOffsetMap.put(DE,+1);  // Germany
timeZoneOffsetMap.put(LI,+1);  // Liechtenstein
timeZoneOffsetMap.put(LU,+1);  // Luxembourg
timeZoneOffsetMap.put(AU,+11); // Australia
timeZoneOffsetMap.put(BE,+1);  // Belgium
timeZoneOffsetMap.put(BW,+2);  // Botswana
timeZoneOffsetMap.put(BZ,-6);  // Belize
timeZoneOffsetMap.put(CA,-6);  // Canada
timeZoneOffsetMap.put(GB,+0);  // United Kingdom
timeZoneOffsetMap.put(HK,+8);  // Hong Kong SAR China
timeZoneOffsetMap.put(IE,+0);  // Ireland
timeZoneOffsetMap.put(IN,+6);  // India
timeZoneOffsetMap.put(JM,-5);  // Jamaica
timeZoneOffsetMap.put(MH,+12); // Marshall Islands
timeZoneOffsetMap.put(MT,+1);  // Malta
timeZoneOffsetMap.put(NA,+1);  // Namibia
timeZoneOffsetMap.put(NZ,+13); // New Zealand
timeZoneOffsetMap.put(PH,+8);  // Philippines
timeZoneOffsetMap.put(PK,+5);  // Pakistan
timeZoneOffsetMap.put(SG,+8);  // Singapore
timeZoneOffsetMap.put(TT,-4);  // Trinidad and Tobago
timeZoneOffsetMap.put(US,-6);  // United States
timeZoneOffsetMap.put(VI,-4);  // U.S. Virgin Islands
timeZoneOffsetMap.put(ZA,+2);  // South Africa
timeZoneOffsetMap.put(FR,+1);  // France
timeZoneOffsetMap.put(BE,+1);  // Belgium
timeZoneOffsetMap.put(NL,+1);  // Netherlands
}

String country = context.getResources().getConfiguration
().locale.getCountry().toUpperCase();
int timeZoneOffset_hours = 0;
if(timeZoneOffsetMap.containsKey(country)) {
timeZoneOffset_hours= timeZoneOffsetMap.get(country);
}

int timeZoneOffset_millisec = timeZoneOffset_hours * 60 * 60 * 1000
long now = System.currentTimeMillis() + timeZoneOffset_millisec;









On Feb 18, 10:12 pm, bw ben.weisb...@gmail.com wrote:
 Hi,

 I can't figure out how to get the local time zone...

 TimeZone.getDefault() returns Pacific Time, while my phone's settings
 show the time zone correctly set to EST.

 Thanks
 -Ben
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---