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!
double seconds = (currentTime - startTime).TotalSeconds;
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With