Reputation: 66565
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!
Upvotes: 5
Views: 9176
Reputation: 171391
double seconds = (currentTime - startTime).TotalSeconds;
Upvotes: 9
Reputation: 42152
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
Upvotes: 3
Reputation: 72850
Try this:
relativeTime.TotalSeconds
This returns whole and fractional, as a double.
Upvotes: 2