0

I know how to calculate the difference between two timespans. But, i can only get one answer. Ms, seconds, minutes etc.

What i want is to compare two timespans, then get the difference in seconds + milliseconds.

Meaning if the difference is 10 seconds and 309 milliseconds, i would get.

10.309 as an answer.

I don´t think showing any codes of mine really matters here, as i got it all working, and it´s only to get the result i would like to know.

If you need anything from my code, please tell.

    TimeSpan first;
    TimeSpan last;

   TimeSpan.TryParseExact(First.Text.Replace("-", ":").Remove(First.Text.LastIndexOf("-"),1).Insert(First.Text.Length-4,"."),"g",CultureInfo.InvariantCulture,out first);
   TimeSpan.TryParseExact(Last.Text.Replace("-", ":").Remove(First.Text.LastIndexOf("-"), 1).Insert(First.Text.Length - 4, "."), "g", CultureInfo.InvariantCulture, out last);
   TimeSpan u = first - last;
   MessageBox.Show(u.TotalMilliseconds.ToString());
Zerowalker
  • 761
  • 2
  • 8
  • 27
  • I don´t refuse, i thought it wasn´t needed, and sorry forgot , it´s c#, will add it as a tag and example of my code. – Zerowalker Aug 03 '13 at 05:54

1 Answers1

1

Use the "F" format specifier:

MessageBox.Show(u.TotalSeconds.ToString("F3"));
Mike Zboray
  • 39,828
  • 3
  • 90
  • 122