.NET custom date time format


I recently found a bug in my software because it was using a custom date time format string DateTime.Now.ToString(“yyyy-MM-dd HH:mm:ss.fff”), which should lead to a date time string like this “2016-01-16 09:47:00.045”.

The time separator “:” however is not absolute, it can output a character such as “.”. So learning from the mistake the previous piece of code is now DateTime.Now.ToString(“yyyy-MM-dd HH’:’mm’:’ss.fff”). This makes the time separator absolute.