9
When calculating the millisecond difference between two DateTime objects I always seem to get a number returned where the decimal part of the number is the same as the integer component of the number. For example: 1235.1235
Why does this happen? Am I doing something wrong? Is this a quirk of the language or a limitation of the DateTime granularity or something?
This can be demonstrated using the following code:
DateTime then = DateTime.Now;
Thread.Sleep(1234);
DateTime now = DateTime.Now;
TimeSpan taken = now - then;
string result = taken.TotalMilliseconds.ToString(CultureInfo.InvariantCulture);
//result = "1235.1235"
As commented by CodesInChaos:
DateTime` isn't accurate to this level of precision: see C# DateTime.Now precision
However - that doesn't quite explain this behavior.