count times together
-
Hi, For a sportevent I need to make to calculate the overall time after each round an this for 15 rounds. The input and output timeformat is "HH:mm:ss:ff" because I need the millisecond precision. Maybe it's a stupid question, but I can't figure out how I can do this. Is there someone who can tell me how I make the sum of 2 different times. so I can start from that point. thanks for the advise. grtz. w
-
Hi, For a sportevent I need to make to calculate the overall time after each round an this for 15 rounds. The input and output timeformat is "HH:mm:ss:ff" because I need the millisecond precision. Maybe it's a stupid question, but I can't figure out how I can do this. Is there someone who can tell me how I make the sum of 2 different times. so I can start from that point. thanks for the advise. grtz. w
TimeSpan
hasAdd
method. Have you checked that?Navaneeth How to use google | Ask smart questions
-
Hi, For a sportevent I need to make to calculate the overall time after each round an this for 15 rounds. The input and output timeformat is "HH:mm:ss:ff" because I need the millisecond precision. Maybe it's a stupid question, but I can't figure out how I can do this. Is there someone who can tell me how I make the sum of 2 different times. so I can start from that point. thanks for the advise. grtz. w
You should parse the string into a timespan object
TimeSpan roundOneTime;
bool success = TimeSpan.TryParse("00:12:34.67", out roundOneTime)You can then easily add the multiple timespan objects together to get your total. (The format required is "HH:mm:ss.ff" (it's a . not a : before the milliseconds, so you'll either need to parse the string and change it first, or change how the strings are built up.
Simon
-
Hi, For a sportevent I need to make to calculate the overall time after each round an this for 15 rounds. The input and output timeformat is "HH:mm:ss:ff" because I need the millisecond precision. Maybe it's a stupid question, but I can't figure out how I can do this. Is there someone who can tell me how I make the sum of 2 different times. so I can start from that point. thanks for the advise. grtz. w
Using the DateTime and TimeSpan objects. http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^] and http://msdn.microsoft.com/en-us/library/system.timespan.aspx[^]
//Create a TimeSpan object to hold Overall Time TimeSpan Overall = new TimeSpan(0,0,0); for (int i = 0; i < NumberOfRounds; i++) { //Each round has a start and end time DateTime Start = DateTime.Now; // Round plays out DateTime End = DateTime.Now; TimeSpan TimeOfRound = End.Subtract(Start); Overall.Add(TimeOfRound); }
Just because we can; does not mean we should.