I want to parse following datetime string "2016-05-31T16:03:39.5173279Z"
and receiving result is not what I would expect, I would expect that hour would be 16 not 18.
Here is a code:
string _UtcFormat= "yyyy-MM-ddTHH:mm:ss.fffffffZ";
DateTime.ParseExact("2016-05-31T16:03:39.5173279Z", _UtcFormat, new System.Globalization.CultureInfo("de-DE"))
Any comments
You need to add DateTimeStyles.AdjustToUniversal
as the last argument of DateTime.ParseExact()
:
DateTime dt = DateTime.ParseExact("2016-05-31T16:03:39.5173279Z", _UtcFormat, new System.Globalization.CultureInfo("de-DE"), DateTimeStyles.AdjustToUniversal);
The bit you've perhaps not noticed is
Kind: Local
By default, ParseExact
will parse the datetime and convert it to your local timezone.
If you want to ignore that, use the overload which allows you to specify DateTimeStyles
- I believe the setting you want is DateTimeStyles.AdjustToUniversal
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With