Search Unity

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

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

  1. PHL1

    PHL1

    Joined:
    Jul 25, 2017
    Posts:
    29
    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,748
    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.
     
    PHL1 likes this.
  3. PHL1

    PHL1

    Joined:
    Jul 25, 2017
    Posts:
    29
    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,748
    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 ^)
     
    PHL1 likes this.
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    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.
     
    PHL1 likes this.
  6. UDN_5c806b49-d8a0-4f67-a296-c12c91aa7396

    UDN_5c806b49-d8a0-4f67-a296-c12c91aa7396

    Joined:
    Jan 9, 2017
    Posts:
    152
    How'd you fix this?