I have process that accepts datetime value with timezone as a string (data comes from outside system). I need to translate this datetime to what the time would have been at the local machines timezone.
Example code:
string cetId = "Central European Standard Time";
if (timeZone == "CET")
{
TimeZoneInfo cetZone = TimeZoneInfo.FindSystemTimeZoneById(cetId);
returnDateTime = TimeZoneInfo.ConvertTime(statusDateTime, cetZone, TimeZoneInfo.Local);
}
else if (timeZone == "CEST")
{
TimeZoneInfo cestZone = TimeZoneInfo.FindSystemTimeZoneById(cetId);
returnDateTime = TimeZoneInfo.ConvertTime(statusDateTime, cestZone, TimeZoneInfo.Local);
}
Do I need to do anything specific if the time is CEST (central european summer time) instead of CET (central european time) or does .net TimeZoneInfo object handle that scenario?
Here’s how to convert the current date and time from the local time zone to another one: [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId( ` (Get-Date), 'Greenwich Standard Time')
This method's parameters are the date and time value to convert, the identifier of the date and time value's time zone, and the identifier of the time zone to convert the date and time value to.
Find the time difference between several cities with the Time Difference Calculator. Provides time zone conversions taking into account daylight saving time (DST), local time zone and accepts present, past or future dates. For current time anywhere in the world, please use The World Clock.
With SWITCHOFFSET (), you must provide the actual time zone offset either in the format [+|-]TZH:TZM or as a signed integer (for minutes). This means you need to know the exact time zone offset, and whether or not that time zone is currently observing daylight savings. With the AT TIME ZONE clause, you don’t need to know that.
You should be fine.
You are telling ConvertTime what both time zones (source and target) are.
Do you have a specific problem with this or are you just asking for confirmation?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With