How to change a past date from local Eastern time to Central European Time while accounting for daylight savings?

Viewed 31

I am new to C# so please excuse me if the question is too simple, I tried the code below and it didn't work

I tried:

//-- Local Time I want to convert
DateTime eventDate1 = new DateTime(2020, 03, 21, 13, 20, 01, DateTimeKind.Local);

//-- Timezone I want to convert to
TimeZoneInfo CentralEurope = TimeZoneInfo.FindSystemTimeZoneById("Central European Time");

//-- Converting local time to Central European Time and returning it as a string 
DateTime targetTime = TimeZoneInfo.ConvertTime(eventDate1, CentralEurope);

return targetTime.ToString("yyyy-MM-ddT00:00:00");
0 Answers
Related