I have code that works great in the emulator but on a 3gs device it crashes with a TimeZoneNotFoundException.
The reason for my code is to convert the server time (given in CET) to the local timezone.
var t = TimeZoneInfo.FindSystemTimeZoneById(TimeZone.CurrentTimeZone.StandardName);
//This line below crashes
double localOffset = t.GetUtcOffset(DateTime.Now).TotalMilliseconds;
The local timezone is in my case CET.
Any idea why this does not work in Monotouch? Is it a limitation of MonoTouch? Since the code works in the emulator, I can not see that it is a programming error? I have tried rewriting this but always end up with the same exception. Also tried “TimeZoneInfo.Local” but that gives the error right away.
Any help is very appreciated!
This was a bug in MonoTouch.
Under the iOS simulator it was possible to re-use the files that contains the time zone data (i.e. just like any UNIX-like system provide). However those files cannot be accessed from an iOS device, leading to the
TimeZoneNotFoundException.Recent MonoTouch releases (5.1.x iirc) are initializing themselves from
NSTimeZonedata so the .NETTimeZoneInfowill have data that match, whatever the iOS version, what the device provides.