Hello, I have an exception when converting local time to UTC. I launched the application on Windows with Russian Standard Time installed.
public Convert()
{
DateTime dt = DateTime.Now;
DateTime dt1 = DateTime.Now;
TimeZoneInfo.ConvertTimeToUtc(dt, TimeZoneInfo.Local);
TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById("Russian Standard Time");
if (TimeZoneInfo.Local.Id == tz.Id)
{
}
TimeZoneInfo.ConvertTimeToUtc(dt1, tz);
}
UPDATE
Exception text - cannot complete coversion because the Kind datetime property is incorrect. For example, if Kind is local, the time zone should be TimeZoneInfo.Local.
Sorry, this is not a copy - the original message is not written in English.
source
share