I am trying to convert the conversion time to the user’s time zone, but I don’t have a Windows time zone line, such as “Standard Pacific Time”. All I have is a string offset, such as "-07: 00".
Then you do not have what it takes to convert correctly. Read "Time Zone! = Offset" in the time zone time wiki .
It is important to understand that the value of "Pacific Standard Time" is the .Id for the TimeZoneInfo object that is used for US Pacific Time. It covers both Pacific Standard Time (UTC-8) and Pacfic Daytime (UTC-7).
All I have is a string offset, such as "-07: 00". Looks like I need to create a time span.
Now you have the so-called XY problem . You should not need to work with the offset yourself.
Your code has a call to dateTime.Add(toUtcOffset) . When converting time zones, it’s the smell of code that you are doing it wrong. You never have to manually add or subtract time to manipulate time zones. This should be reserved for actually changing the point in time you are talking about.
What you should do is collect the real-time identifier from the user. Either "Pacific Standard Time" for use with TimeZoneInfo , or "America/Los_Angeles" for use with the TZDB implementation, such as Noda Time .
If conversions in the time zone are not important in your context, you might just want to collect the full DateTimeOffset value, for example 2013-08-17T13:27:00.000-07:00 .
source share