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 8255905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:41:20+00:00 2026-06-08T01:41:20+00:00

I am compiling in C# using .NET 3.5 and am trying to convert a

  • 0

I am compiling in C# using .NET 3.5 and am trying to convert a TimeSpan to a string and format the string. I would like to use

myString = myTimeSpan.ToString("c");

however the TimeSpan.ToString method does not take a format string as an argument until .NET 4.0 and I am using .NET 3.5.

How then would you format a TimeSpan as a string? My final goal is to display the TimeSpan in format hh:mm:ss but am currently receiving hh:mm:ss:fffffff.

I have tried using

myString = string.Format("{0:hh:mm:ss}", myTimeSpan);

but string.Format is only formatting my DateTime and passing different format strings doesn’t work when trying to format a TimeSpan.

  • 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-06-08T01:41:22+00:00Added an answer on June 8, 2026 at 1:41 am

    One way could be:

    TimeSpan ts = DateTime.Now - DateTime.Now.AddHours(-10);
    Console.WriteLine(string.Format("{0:00}:{1:00}:{2:00}", ts.TotalHours, ts.Minutes, ts.Seconds));
    

    Result would be something like:

    09:59:59
    

    EDIT:

    Or you can try:

    TimeSpan ts = DateTime.Now - DateTime.Now.AddHours(-10);
    DateTime mydate = new DateTime(ts.Ticks);
    Console.WriteLine(mydate.ToString(("hh:mm:ss")));
    

    Output would be:

    09:59:59
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a VB.net program via a text file and I'm compiling it using
I'm trying to use Subsonic 3.0.0.3 with an existing web site created in vb.net.
We have a .NET 1.1 solution that we are compiling using NAnt with a
I am trying to get a simple prototype using ASP.NET S#arp-architecture (Sharp architecture) to
Briefly: I'm after the equivalent of .NET's String.Trim in C using the win32 and
I am implementing the SMPP client using EasySMPP for .NET The application is compiling
I am compiling a .Net project on Linux, using monodevelop. I get the following
I am compiling third party C++ code using /CLR flag which requires only .NET
I want to make myself a simple webapp using vb.net.I am trying to make
I'm trying to compile enc2ly ( http://enc2ly.sourceforge.net/en/ ) on Windows using cygwin but it

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.