Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6112089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:42:18+00:00 2026-05-23T14:42:18+00:00

I wrote a function which does this functionality and I am not satisfied with

  • 0

I wrote a function which does this functionality and I am not satisfied with the performance & implementation. I wanted to see if someone can help me implement this nifty functionality in an efficient way.

The function should return a string which is the average time between 2 timer values passed. 2 timer values are both strings of the format "MM:SS:HS" for example if values "02:02:20" and "04:04:40" are passed to the function it should output the average time between those values and return it as a string in the same format "03.03.30".

I wanted to implement it in C#, Java is fine too.

Look forward to your solutions. Thanks for reading!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:42:18+00:00Added an answer on May 23, 2026 at 2:42 pm
    • Use TimeSpan.Parse to parse the two values
    • Add them together
    • Take the number of ticks of the sum (TimeSpan.Ticks) and divide it by two to get the average (as you can’t divide a TimeSpan directly)
    • Use TimeSpan.FromTicks to convert back to a TimeSpan
    • Call ToString to convert back from a TimeSpan to a string.

    (I’m not sure why the other answers are suggesting subtraction, when a mean value is usually gained by adding values and then dividing…)

    Personally I’d probably split this into two methods, one of which just did the averaging part, and the other of which did the text conversions:

    public static TimeSpan Average(TimeSpan first, TimeSpan second)
    {
        return TimeSpan.FromTicks((first + second).Ticks / 2);
    }
    
    public static string Average(string first, string second)
    {
        TimeSpan firstSpan = TimeSpan.Parse(first);
        TimeSpan secondSpan = TimeSpan.Parse(second);
        return Average(firstSpan, secondSpan).ToString();
    }
    

    You may need to mess around a bit to get the exact text format you want – there are more options in .NET 4 than previously, using ToString with a format string etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a function which can yield the text of a tree view item,
I wrote a function in Python which is used to tell me whether the
I want to write a function which can validate a given value (passed as
How can I write a function which will return pi (π) to a given
I want to write a function that accepts a parameter which can be either
I wrote a multi-threaded program which does some CPU heavy computation with a lot
I am exploring parent process & child processes concept in UNIX. I wrote this
I wrote this little function for writing out HTML tags: def html_tag(tag, content=None, close=True,
I wrote a simple winforms application which does some task every 30 seconds (using
Apologies for asking such a primitive question. I wrote a function which took one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.