TimeSpan

  • Thread starter Thread starter pete
  • Start date Start date
P

pete

I need to take many TimeSpan values and find their
average. I know you can Add the many values together, but
how do you then divide that result by the count of values
that you had? Once I have the average, how can I display
the result in a reasonable way? Thanks in advance.
 
pete said:
I need to take many TimeSpan values and find their
average. I know you can Add the many values together, but
how do you then divide that result by the count of values
that you had? Once I have the average, how can I display
the result in a reasonable way? Thanks in advance.

It's probably easiest to sum their Ticks values, then create a new
TimeSpan with the average number of ticks.

As for formatting: for some reason TimeSpan doesn't provide the normal
formatting services, so unless the display format it provides with
ToString does what you want, you'll have to generate your own format
using the properties it provides (Minutes, Hours etc).
 
Back
Top