Convert ISO 8601 string into TimeZone Info

My client app is sending me a date string using ISO 8601 format. I can get a DateTime using,

DateTime.Parse(date, null, DateTimeStyles.RoundtripKind);

How to create a .NET DateTime from ISO 8601 format

Now, I wanna know time zone from the string that client is sending. For example, 2022-07-28T01:00:00+02:00 this means client is +2 hours from UTC.

Upvotes: 1

Views: 848

Answers (1)

Dave Van den Eynde
Dave Van den Eynde

Reputation: 17445

Don't use the DateTime type. It doesn't know the offset. Use the DateTimeOffset type.

var dateTimeOffset = DateTimeOffset.Parse(date);

Now you can find the offset in the Offset property.

Upvotes: 4

Related Questions