Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading