I’m trying to convert the current time to Central Standard Time. With Mono and .NET, these both work.
TimeZoneInfo cst = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
TimeZoneInfo.ConvertTime(DateTime.UtcNow, cst);
TimeZoneInfo.ConvertTime(DateTime.Now, cst);
With MonoDroid 3.0.4, the first one give this error:
Unhandled Exception:
System.ArgumentException: Kind propery of dateTime is Utc but the sourceTimeZone does not equal TimeZoneInfo.Utc
at System.TimeZoneInfo.ConvertTime (DateTime dateTime, System.TimeZoneInfo sourceTimeZone, System.TimeZoneInfo destinationTimeZone) [0x00000] in <filename unknown>:0
at System.TimeZoneInfo.ConvertTime (DateTime dateTime, System.TimeZoneInfo destinationTimeZone) [0x00000] in <filename unknown>:0
and the second gives this error:
Unhandled Exception:
System.ArgumentNullException: Argument cannot be null.
Parameter name: destinationTimeZone
at System.TimeZoneInfo.ConvertTime (DateTime dateTime, System.TimeZoneInfo sourceTimeZone, System.TimeZoneInfo destinationTimeZone) [0x00000] in <filename unknown>:0
at System.TimeZoneInfo.ConvertTime (DateTime dateTime, System.TimeZoneInfo destinationTimeZone) [0x00000] in <filename unknown>:0
Same problems with TimeZoneInfo.ConvertTimeBySystemTimeZoneId.
Anyway to get the current time in different timezones with MonoDroid?
One possible workaround is to call the three-parameter version yourself:
EDIT:
FindSystemTimeZoneByIdshould throw aTimeZoneNotFoundExceptionif it doesn’t find the zone you’re interested in, but I wonder whether in this case it’s just returningnull.It’s possible that the time zone IDs on MonoDroid are the TZDB ones, in which case you could try using: