How can I exactly construct a time stamp of actual time with milliseconds precision?
I need something like 16.4.2013 9:48:00:123. Is this possible? I have an application, where I sample values 10 times per second, and I need to show them in a graph.
try using datetime.now.ticks. this provides nanosecond precision. taking the delta of two ticks (stoptick - starttick)/10,000 is the millisecond of specified interval.
https://docs.microsoft.com/en-us/dotnet/api/system.datetime.ticks?view=netframework-4.7.2
I was looking for a similar solution, base on what was suggested on this thread, I use the following
DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff")
, and it work like charm. Note: that.fff
are the precision numbers that you wish to capture.Pyromancer's answer seems pretty good to me, but maybe you wanted:
But if you are comparing dates, TimeSpan is the way to go.
Use DateTime Structure with milliseconds and format like this:
DateTime.Now.ToString("ddMMyyyyhhmmssffff")
If you still want a date instead of a string like the other answers, just add this extension method.