Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

TimeZoneInfo.FindSystemTimeZoneById(timeZoneName) Working on Windows But Not In Android!

Discussion in 'Scripting' started by Ina_Sh, Aug 23, 2019.

  1. Ina_Sh

    Ina_Sh

    Joined:
    Jul 25, 2017
    Posts:
    9
    Hello. this line of code works fine on Windows:
    TimeZoneInfo.FindSystemTimeZoneById(timeZoneName)


    but in Android Build i get this error:

    Directory not found exception: could not find a part of the path "/usr/share/zoneinfo/timeZoneName
     
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,280
    Not all .NET features are compatible with all platforms unity runs on. Looks like this is not supported one. You extract time zones infos into scriptable objects and load them in player on demand.
     
    Ina_Sh likes this.
  3. Ina_Sh

    Ina_Sh

    Joined:
    Jul 25, 2017
    Posts:
    9
    thanks for the response. actually, that crossed my mind too. can you suggest a fast way to do that? I tried to get a JSON string out of the object but looks like it is not serializable!. so any other way? (i need only time zone info of one area)
     
  4. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,280
    If only one, then just configure it manually. If many, write script doing the same you would do for one. It is workiking on windows so just get data and save it for use anywhere ^)
     
    Ina_Sh likes this.
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    6,520
    Not sure what you're trying to do with this information, but you might get what you are looking for by comparing DateTime.Now to DateTime.UtcNow to figure out the offset, or using some of the options in DateTime.Now.ToString to get it to output the time zone offset which you'd then have to parse.

    Alternatively, I'd guess writing a native android plugin for Unity which just provides the time zone would be rather trivial as far as android plugins go.
     
    Ina_Sh likes this.