Despite what people are saying on the net, you do not need to write your own method to include milliseconds when formatting a
DateTime object. To achieve this, you can use the
f modifier. For example, if you want to include thousands of a second (i.e. milliseconds), you can write something like this:
You can set the fractional part to include up to 7 digits:
If you try more, it will raise an exception. Luckily, in basic scenarios, you do not need that.