I need to convert DateTime+TimeZoneInfo into DateTimeOffset.
How do I do this? I assume I have to pass TimeSpan but then I'm not sure if daylight saving times will be handled properly..
Thanks!
UPDATE
TimeZoneInfo timeZone = TimeZoneInfo.FindSystemTimeZoneById("Mountain Standard Time");
return new DateTimeOffset(DateTime.UtcNow, timeZone.BaseUtcOffset);
This code throws exception..
The UTC Offset for Utc DateTime instances must be 0.\r\nParameter name: offset
UPDATE 2
Sorry, I didn't realize that DateTimeOffset contains only offset, it doesn't contain actual zone information - so I'm accepting answer from @Dave as it is what I will be using..
DateTime.Now
, notDateTime.UtcNow
. – OdedTimeZoneInfo
- just create a newTimeSpan
with all fields set to 0. – Oded