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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:44:22+00:00 2026-06-10T02:44:22+00:00

I created a TimeSpan this way TimeSpan ts = new Timespan(); // Do some

  • 0

I created a TimeSpan this way

TimeSpan ts = new Timespan();

// Do some addition and subtraction on it

Then I am saving it to a file using this

string.Format("{0}:{1}:{2}:{3}", ts.Hours, ts.Minutes, ts.Seconds, ts.MilliSeconds);

Various values returned from it are like this

0:0:4:410
0:0:1:425
0:0:1:802
0:0:1:509
0:0:1:674
0:0:1:628
0:0:2:76

How to convert it back to TimeSpan.

I am using

TimeSpan.ParseExact("0:0:4:410", "h:m:s:fff", null); 

but it is giving me error Input String is not in correct format.

Where am I wrong?

  • 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-10T02:44:23+00:00Added an answer on June 10, 2026 at 2:44 am

    I believe you need to parse the colons, basically. I would also suggest using the invariant culture instead of the current thread culture:

    var ts = TimeSpan.ParseExact("0:0:4:410", @"h\:m\:s\:fff",
                                 CultureInfo.InvariantCulture);
    

    From the documentation:

    The custom TimeSpan format specifiers do not include placeholder separator symbols, such as the symbols that separate days from hours, hours from minutes, or seconds from fractional seconds. Instead, these symbols must be included in the custom format string as string literals. For example, “dd.hh:mm” defines a period (.) as the separator between days and hours, and a colon (:) as the separator between hours and minutes.

    I would also suggest using a format of h:mm:ss.fff instead – I believe this would be clearer than your current format. Note that you can use the format directly instead of your currently formatting approach:

    const string TimeSpanFormat = @"h\:mm\:ss\.fff";
    
    string text = ts.ToString(TimeSpanFormat, CultureInfo.InvariantCulture);
    ...
    TimeSpan parsed = TimeSpan.ParseExact(text, TimeSpanFormat,
                                          CultureInfo.InvariantCulture);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have this code: static void Main(string[] args) { var thread = new
I have created the following test program: static void Main(string[] args) { using (var
I created a python server on port 8000 using python -m SimpleHTTPServer . When
I created a new product type and everything works except the indexing of the
I'm using Quartz.NET for job scheduling in my ASP.NET application, and I have created
I am using a named system mutex to synchronise 2 processes. This is how
I have and built and deployed the application created by the new project template
this is weird to me, it's got to be something obvious but when using
I created a File Cleanup Provider that is inherits system.web.management.webeventprovider. Public Class FileCleanupProvider Inherits
I've created a small app that watches an inbox using the EWS managed dll.

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.