Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. count times together

count times together

Scheduled Pinned Locked Moved C#
question
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    redspiderke
    wrote on last edited by
    #1

    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

    N S K 3 Replies Last reply
    0
    • R redspiderke

      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

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      TimeSpan has Add method. Have you checked that?

      Navaneeth How to use google | Ask smart questions

      1 Reply Last reply
      0
      • R redspiderke

        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

        S Offline
        S Offline
        Simon P Stevens
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • R redspiderke

          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

          K Offline
          K Offline
          KaptinKrunch
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups