draksia
draksia

Reputation: 2371

TimeZone.getRawOffset() doesn't appear to be working in Android 4.2

TimeZone tz = TimeZone.getTimeZone(TimeZoneString);
timeZoneOffsetms = tz.getRawOffset();

The values for TimeZoneString are in the format "GMT+02:00:00"

The previous code was working from 2.2 - 4.1 with not issues.

Now with 4.2 it always returns an offset equal to 0 whether the time zone is ahead or behind UTC.

Any ideas or any one else seen this.

Upvotes: 2

Views: 694

Answers (1)

draksia
draksia

Reputation: 2371

After checking the source for TimeZone there was a significant change in 4.2. The class began enforcing a regex that only requires hours and minutes. Supplying the seconds would result in it failing the regex pattern matcher and then returning null.

The solution on my side is check the value from my server for seconds and remove if they are specified. Since I don't have any control the value returned from the server is.

I hope this helps if any one else has run into the issue.

Upvotes: 2

Related Questions