This page looks best with JavaScript enabled

VB.NET - Format DateTime With Milliseconds

 ·   ·  ☕ 1 min read

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:

1
Now.ToString(“HH:mm:ss.fff”)

You can set the fractional part to include up to 7 digits:

1
Now.ToString(“HH:mm:ss.fffffff”)

If you try more, it will raise an exception. Luckily, in basic scenarios, you do not need that.


Victor Zakharov
WRITTEN BY
Victor Zakharov
Web Developer (Angular/.NET)