Android TimeZone Turkey GMT

2019-07-03 13:07发布

For 2016 Turkish Government decided to stay GMT+3 timezone to save daylight, but on android:

Calendar calendar = Calendar.getInstance();
TimeZone tz = TimeZone.getTimeZone("UTC");
calendar.setTimeInMillis(timestamp * 1000);
Date currentTimeZone = (Date) calendar.getTime();
calendar.add(Calendar.MILLISECOND, tz.getOffset(calendar.getTimeInMillis()));

So the problem is;
it's showing GMT+3 for the date before November:
Wed Oct 26 18:00:00 GMT+03:00 2016
but for after November:
Mon Nov 07 20:00:00 GMT+02:00 2016

it should've stay at GMT+3 for the whole year, is that a special issue to android lib of TimeZone or am I doing something wrong?
Thanks,

UPDATE
Although I've added a check for timezone and gmt parameters,
The situation will be a little chaotic for the Android devices that uses Turkey's timezone, cause after Oct 29 the hour of device will be an hour early than normal, until Android releases a update for that and user applies that.

1条回答
一夜七次
2楼-- · 2019-07-03 13:41

See the release note of tzdb-database for version 2016g:

Release 2016g - 2016-09-13 08:56:38 -0700

Changes to future time stamps

Turkey switched from EET/EEST (+02/+03) to permanent +03,
effective 2016-09-07.  (Thanks to Burak AYDIN.)  
Use "+03" rather than an invented abbreviation for the new time.

Obviously, your Android device still uses an outdated timezone version. Actually you have following options to proceed:

  • Wait for a new Android version (not attractive, not recommended).
  • Use another external library like Joda-Time-Android or my library Time4A which already use 2016h (Threeten-ABP is still behind, actually on 2016e).
  • Or write your own hack using fixed offsets for Turkey, for example TimeZone.getTimeZone("GMT+03")
查看更多
登录 后发表回答