Home > Net >  Convert ISO 8601 string into TimeZone Info
Convert ISO 8601 string into TimeZone Info

Time:08-01

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.

CodePudding user response:

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.

  • Related