Hello I have an exception when converting local time to UTC. I run my application on Windows where "Russian Standard Time" is set.
public Convert()
{
DateTime dt = DateTime.Now;
DateTime dt1 = DateTime.Now;
// this converstion works
TimeZoneInfo.ConvertTimeToUtc(dt, TimeZoneInfo.Local);
// now let's get local timezone by id
TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById("Russian Standard Time");
if (TimeZoneInfo.Local.Id == tz.Id)
{
// this is just to make sure we have the same timezones
}
// this conversion does not work
// throws exception System.ArgumentException
TimeZoneInfo.ConvertTimeToUtc(dt1, tz);
}
UPDATE
Exception text is saying - cannot complete coversion because Kind property of datetime is wrong. For example if Kind is Local the timezone must have value of TimeZoneInfo.Local.
Sorry this is not a copypaste - original message is not in english.