Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Timespan Milliseconds vs TotalMilliseconds

Tags:

c#

.net

timespan

In the example below, why does the Milliseconds property return 0 but the TotalMilliseconds property return 5000?

// 5 seconds TimeSpan intervalTimespan = new TimeSpan(0, 0, 5);  // returns 0 intervalTimespan.Milliseconds;  // returns 5000.0 intervalTimespan.TotalMilliseconds 
like image 958
AJM Avatar asked Mar 30 '11 09:03

AJM


2 Answers

Simple:

  • Milliseconds are the remaining milliseconds, that don't form a whole second.
  • TotalMilliseconds is the complete duration of the timespan expressed as milliseconds.
like image 167
Daniel Hilgarth Avatar answered Sep 20 '22 17:09

Daniel Hilgarth


Because Milliseconds returns the Milliseconds portion, and TotalMilliseconds returns the total milliseconds represented by the Timespan

Example: 0:00:05.047

Milliseconds: 47

Total Milliseconds: 5047

like image 33
kͩeͣmͮpͥ ͩ Avatar answered Sep 20 '22 17:09

kͩeͣmͮpͥ ͩ