c# - TimeZoneInfo.FindSystemTimeZoneById() throws exception in a Unity application -
if execute code in c# console application, works fine.
timezoneinfo easternzone = timezoneinfo.findsystemtimezonebyid("eastern standard time"); console.writeline(easternzone.displayname);
however, when use same method in unity application, exception thrown:
system.timezonenotfoundexception: exception of type 'system.timezonenotfoundexception' thrown. @ system.timezoneinfo.findsystemtimezonebyfilename (system.string id, system.string filepath) [0x00000] in <filename unknown>:0 @ system.timezoneinfo.findsystemtimezonebyid (system.string id) [0x00000] in <filename unknown>:0 ...
a curious thing i've noticed exception thrown in method named "findsystemtimezonebyfilename" when msdn documentation explicitly says information retrieved registry.
unity applications use mono, , can target non-windows systems - registry information not available. appears mono use whatever time zone information available on system, whether happens windows time zones, or iana time zones - so, may need check 1 or other, or both:
timezoneinfo easternzone; try { easternzone = timezoneinfo.findsystemtimezonebyid("eastern standard time"); } catch (timezonenotfoundexception) { easternzone = timezoneinfo.findsystemtimezonebyid("america/new_york"); }
of course, can reverse these if typically going running on non-windows platforms. if neither found, still throw exception.
you can review the list of iana time zones here. may want read the timezone tag wiki understand distinction.
Comments
Post a Comment