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

  • Home
  • SEARCH
  • 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 4102216
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:47:50+00:00 2026-05-20T20:47:50+00:00

Typing in the title to this question brought me to this question . I’m

  • 0

Typing in the title to this question brought me to this question. I’m looking for the same thing, but something perhaps less statically formatted if you get what I mean?

I’m writing a quick program that will be taking a TimeSpan duration of two DateTime objects and outputting them for printing to paper.

The format that would be preferred is: XX days, YY hours, ZZ minutes (seconds are irrelevant; as are days because I don’t expect the timespan to incorporate more than a few hours).

Say the following code (as an example):

DateTime start = DateTime.Now;
DateTime end = DateTime.Now.AddMinutes(135);
TimeSpan duration = (end - start);

// output duration as XX hours, YY minutes

Thanks,
Zack

P.S.
I also ran across “PrettyTime.NET“, but it output things like “3 days ago”, etc. Every other topic I found on google to format time duration strings like the above examples lead me to a Java-based solution. :\


UPDATE 2014-09-08:

To follow-up after 3 years, I’ve found an awesome library on NuGet and Github called “Humanizer” which would solve this issue I was having. I haven’t used it that much, but I did try it and it works beautifully. It’s quite large of a library though (it emits a whole ton of folders for different cultures to your project’s build path (I’m sure there’s a way to to customize it)).

  • 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-20T20:47:51+00:00Added an answer on May 20, 2026 at 8:47 pm

    And if you care about pluralization:

    public static string ToPrettyFormat(this TimeSpan span) {
    
        if (span == TimeSpan.Zero) return "0 minutes";
    
        var sb = new StringBuilder();
        if (span.Days > 0)
            sb.AppendFormat("{0} day{1} ", span.Days, span.Days > 1 ? "s" : String.Empty);
        if (span.Hours > 0)
            sb.AppendFormat("{0} hour{1} ", span.Hours, span.Hours > 1 ? "s" : String.Empty);
        if (span.Minutes > 0)
            sb.AppendFormat("{0} minute{1} ", span.Minutes, span.Minutes > 1 ? "s" : String.Empty);
        return sb.ToString();
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Typing out the title to this leads me to believe this might not be
If I start typing stackov.. in Chrome I can see something like 'Press Tab
I know at first glance (due to the title) this looks like one of
i have this problem, im using live preview, while the user is typing they
The title is not exact, but I can't express it better in a single
I am using MVC, not that this makes a difference, but I have a
When typing code, I would normally close brackets, go back inside, go outside, type
When typing in my URL SalaryFor/Microsoft/Balmer i need to display salary for user with
Predictive typing is a handy feature on many mobile phones. How would/can you implement
If the user begins typing, and the focus happens to not be on the

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.