TimeZone.getDefault () does not give me the time zone where I

This hardcoded GMT+2 works like a charm.

 calendarCurrent.setTimeZone(TimeZone.getTimeZone("GTM+2")); 

Of course, I don’t need it hardcoded, so I use

 calendarCurrent.setTimeZone(TimeZone.getDefault()); 

But that never gives me proper value. Am I doing something wrong?

+4
source share
1 answer

The default time zone will be automatically detected by the system, so you do not need to explicitly specify TimeZone.setDefault ().

Automatic time zone detection does not work on the emulator, but you can use the "timezone" start flag to set it.

In addition, the recommended way to change the time zone is the settings application, which is not included in the current sdk .. At the moment, you can use the following:

 AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alarm.setTimeZone(timezone); 

He works with

<uses-permission android:name="android.permission.SET_TIME_ZONE"/>

-1
source

All Articles