PM. PM. - 8 days ago 7
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


20110713014230.685+0000


And format of this is like:


yyyyMMddHHmmss.fff+zzzz


I tried DateTime.ParseExact and DateTimeOffset.ParseExact with/without
+
and
.
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

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.

Comments