Sandokan Sandokan - 4 years ago 192
Vb.net Question

How to get Date.Now with milliseconds?

I need to generate the current Date in vb.net that's have also the millisecond. Actually I use:

Date.Now


but this return a simple date as 28/12/2015 16:53, I want also the millisecond something like:


28/12/2015 16:53:48640864


I tried with:

Public Shared Function MillisecondsDate()

Return Date.Now.ToString("HH:mm:ss.fffffff")

End Function


but this return a bad result:


16:53:56.9884043


I need a format compatible with
MySql
for an accurate
lastUpdated
field. Any ideas?

Answer Source

Try this function:

Public Shared Function MillisecondsDate()
    Return DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fff")
End Function
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download