hello again my question if it is possible to print microsencods using TimesSpan in C#.
i have the next example:
DateTime startTime = DateTime.Now;
..../some code
DateTime endTime = DateTime.Now;
TimeSpan totalTimeTaken = endTime.Subtract(startTime);
Label3.Text=(totalTimeTaken.Milliseconds).ToString();
this code allows me to display in milliseconds but i need to display Microseconds is there a way to change it to Microseconds or do I have to use something else?
have to edit my question: my goal is to measure the time that is spent between the 2 DateTime, since it is very few lines of code the milliseconds just wont cut it, thats the reason i need the microseconds.
TimeSpan
by itself does support this granularity - it's a simple little structure with ticks granular to one tenth of a microsecond. The problem lies with theDateTime
: its granularity is much worse. – FamulusTimeSpan
is, say,00:00:02.3456789
, theMilliseconds
property will only give you the part345
, as anInt32
(int
). What you want isTotalMilliseconds
. That's aDouble
and will include all the digits. See my answer. – JammiejamminTimeSpan
has a bug as well: github.com/dotnet/corefx/issues/32430 – Riggall