Hi
I am converting the DateTime from local time to utc and time zone am passing is est
The date time which i am passing is (06/29/2022 01:00:00 AM) after conversion its showing (06/29/2022 05:00:00 AM), but for 1:00:00 AM local time to est is 3:30 PM but its showing 5:00 AM.
GMT_Standard_Time = "GMT Standard Time"
dtLocaltime = 6/29/2022 1:00:00 AM
strTimezone = Eastern Standard Time
Its showing this -> 6/29/2022 5:00:00 AM
What conversion is happening here?
Why it’s showing this wrong time?
Could you please explain me this?
public static DateTime ConvertLocalTimeToUTC(DateTime dtLocalTime, string strTimezone)
{
TimeZoneInfo timeZoneInfo;
DateTime dtUTCTime = new DateTime();
DateTime dtTimezoneTime;
if (strTimezone != "")
{
try
{
//select * from FEV_TIMEZONE where timezone='CST' and timezone_id in(68,69);
//FindSystemTimeZoneById in the list Mexico is optional so will not get the result
if (strTimezone == "Mexico Standard Time")
strTimezone = "Central Standard Time";
//select * from FEV_TIMEZONE where utc_offset='-07:00:00' and timezone_idin(72,73);
if (strTimezone == "Mexico Standard Time 2")
strTimezone = "Mountain Standard Time";
if (GMT_Standard_Time == strTimezone)
{
dtUTCTime = dtLocalTime;
}
else
{
timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(strTimezone);
dtUTCTime = TimeZoneInfo.ConvertTimeToUtc(dtLocalTime, timeZoneInfo);
}
}
catch (Exception ex)
{
timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(strTimezone);
dtTimezoneTime = TimeZoneInfo.ConvertTime(dtLocalTime, timeZoneInfo);
dtUTCTime = TimeZoneInfo.ConvertTimeToUtc(dtTimezoneTime, timeZoneInfo);
}
}
return dtUTCTime;
}
Above is my code.