Question

I have to calculate the relative time which is

TimeSpan relativeTime = currentTime.Subtract(startTime);

Next I would like to convert relativeTime to double value which should be consisted of seconds and milliseconds (seconds.milliseconds).

Does anyone know what is the best way to generate such double value from time difference?

Thanks!

Was it helpful?

Solution

double seconds = (currentTime - startTime).TotalSeconds;

OTHER TIPS

Eh, TimeSpan.TotalSeconds. Or if you explicitly want to attempt a granularity of milliseconds (not totally possible with double), then:

((long) relativeTime.TotalMilliseconds) / 1000.0

Try this:

relativeTime.TotalSeconds

This returns whole and fractional, as a double.

timeSpan.TotalSeconds

Unless I'm missing something:

t.TotalSeconds;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top