Convert from BST to CST in C#

Viewed 33

I am converting time from BST to CST, It's working as expected for me.

string inputDate = "2209210940";
DateTime gmtTime = DateTime.ParseExact(inputDate, "yyMMddHHmm", CultureInfo.InvariantCulture);
TimeZoneInfo gmtTimeZone = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");
TimeZoneInfo centralTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
var time = TimeZoneInfo.ConvertTime(gmtTime, gmtTimeZone, centralTimeZone);

bool isDayLightSavingTimeGMT = gmtTimeZone.IsDaylightSavingTime(new DateTime(2022, 09, 21, 09, 40, 00));
bool isDayLightSavingTimeCST = centralTimeZone.IsDaylightSavingTime(new DateTime(2022, 09, 21, 09, 40, 00));

I also have checked properties, both are in DayLightSavingTime now.

I also tested by changing the date time to 2201210940 (above both time zones are not in DayLightSaving that time), and this value also worked as expected.

I also have tested my changes by changing CEST to IST (there is no daylight saving concept in IST), which is also working as expected.

I am just curious to know if there is any case in which I am missing or if I need to handle it explicitly.

I am also curious to know that Is there a way to confirm whether the output is correct or now, for now, I am using this website to manually verify the times.

I am using .net 4.7.2

enter image description here

0 Answers
Related