1

TimeZoneInfo.GetSystemTimeZones().Count gives 0 for unity android app, is there any permission required from android side to get TimeZone data?

Debug.LogError("GetSystemTimeZones... " + System.TimeZoneInfo.GetSystemTimeZones().Count);

Output : GetSystemTimeZones... 0

saeed foroughi
  • 1,662
  • 1
  • 13
  • 25
  • There is a Unity Issue on the matter, it seems that it was not yet fixed but on the comments you can find more about it and probably a workaround: https://issuetracker.unity3d.com/issues/win-system-dot-timezoneinfo-does-not-return-any-time-zones – Vitor Figueredo Jan 22 '20 at 13:06
  • @VitorFigueredo this only happens in android app where as **iOS** version of same app works fine. – SagarAnjWebTech Jan 22 '20 at 13:12

2 Answers2

1

I think this method always returns 0 on Android. Reading on the Documentation for TimeZoneInfo:

The GetSystemTimeZones method retrieves all available time zone information from the subkeys of the registry's HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Time Zones key on Windows systems and from the ICU Library on Linux and macOS.

As you can see, Android is not mentioned.

Andrea
  • 6,032
  • 2
  • 28
  • 55
1

based on the documentation it is supposed to return 0 in android! but I saw some people do a workaround to solve this problem. it goes as follow: you can create a jar with Android Studio and get the timezones you need there and then create a C# script to access that jar file. here you can find a toturial on how to do it.

although in this scenario there is a drawback, you can only pass Strings with this solution.

saeed foroughi
  • 1,662
  • 1
  • 13
  • 25