PM. PM. - 1 year ago 207
C# Question

Datetime conversion with milliseconds and timezone

I found many questions about parsing datetime from various formats, but not able to find the solution to my problem of converting datetime string with milliseconds and timezone both.

My input is like


And format of this is like:


I tried DateTime.ParseExact and DateTimeOffset.ParseExact with/without
but nothing worked.

Found similar question Here but it's not working for me.

I get the exception

An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll

Answer Source

Change the format to yyyyMMddHHmmss.fffzzzzz, acording the documentation, the "zzz" custom format specifier represents the signed offset of the local operating system's time zone.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download