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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:01:23+00:00 2026-06-06T15:01:23+00:00

TimeSpan.Parse(23:00:00) returns 23 hours. TimeSpan.Parse(24:00:00) returns 24 days! I realize that I made a

  • 0

TimeSpan.Parse(“23:00:00”) returns 23 hours.

TimeSpan.Parse(“24:00:00”) returns 24 days!

I realize that I made a mistake in that the allowable range of hours is 0-23. But for minutes and seconds if you attempt to parse an out of range value you get an exception. In the case of hours with an out of range value, the parser incorrectly assumes you meant days instead of hours.

Can someone explain this?

This example here covers this very topic and indicates that
http://msdn.microsoft.com/en-us/magazine/ee309881.aspx

The same appears to be true about TryParse. I get 24 days despite the docs stating that the parse should fail.

http://msdn.microsoft.com/en-us/library/3z48198e

//            String to Parse                TimeSpan
//            ---------------   ---------------------
//                          0        00:00:00
//                         14     14.00:00:00
//                      1:2:3        01:02:03
//                  0:0:0.250        00:00:00.2500000
//             10.20:30:40.50     10.20:30:40.5000000
//        99.23:59:59.9999999     99.23:59:59.9999999
//        0023:0059:0059.0099        23:59:59.0099000
//                     23:0:0        23:00:00
//                     24:0:0   Parse operation failed.
//                     0:59:0        00:59:00
//                     0:60:0   Parse operation failed.
//                     0:0:59        00:00:59
//                     0:0:60   Parse operation failed.
//                        10:   Parse operation failed.
//                       10:0        10:00:00
//                        :10   Parse operation failed.
//                       0:10        00:10:00
//                     10:20:   Parse operation failed.
//                    10:20:0        10:20:00
//                       .123   Parse operation failed.
//                    0.12:00        12:00:00
//                        10.   Parse operation failed.
//                      10.12   Parse operation failed.
//                   10.12:00     10.12:00:00

Did I find a bug or am I doing something wrong?

EDIT:
I’ve tested this in LinqPad and using a Console app in .NET4 on Windows 7 64bit.

            var result = TimeSpan.Parse("24:00:00");
            Console.WriteLine(result);
            result = TimeSpan.Parse("24:00:00", CultureInfo.InvariantCulture);
            Console.WriteLine(result);

This results in:

24.00:00:00
24.00:00:00
  • 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-06T15:01:24+00:00Added an answer on June 6, 2026 at 3:01 pm

    What’s going on is that TimeSpan.Parse attempts to parse ##:##:## using each of the following formats in order, stopping as soon as one succeeds:

    1. hh:mm:ss (invariant culture)
    2. d.hh:mm (invariant culture)
    3. hh:mm:ss (localized)
    4. d.hh:mm (localized; more details about the “.” below)

    So:

    • 23:08:09 is successfully parsed as 0d 23h 8m 9s in Step 1.
    • 24:08:09 is successfully parsed as 24d 8h 9m 0s in Step 4.

    If this behavior doesn’t suit you, you can use TimeSpan.ParseExact instead:

    TimeSpan.ParseExact("23:00:00", "hh':'mm':'ss", null) // OK
    TimeSpan.ParseExact("24:00:00", "hh':'mm':'ss", null) // OverflowException
    

    UPDATE: According to the documentation for TimeSpan.Parse, the “.” between “d” and “hh” is

    A culture-sensitive symbol that separates days from hours. The invariant format uses a period (“.”) character.

    However, I dug into the framework source with Reflector, and it turns out that, in the localized format, this alleged “culture-sensitive” symbol is always a colon! Here’s an excerpt from the internal DateTimeFormatInfo.FullTimeSpanPositivePattern property:

    string separator = new NumberFormatInfo(cultureData).NumberDecimalSeparator;
    this.m_fullTimeSpanPositivePattern = "d':'h':'mm':'ss'" + separator + "'FFFFFFF";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The TimeSpan class can be constructed with days, hours, minutes, seconds and milliseconds: public
I am trying to format a TimeSpan element in the format of [minutes]:[seconds]. In
How to parse string like 30:15 to TimeSpan in C#? 30:15 means 30 hours
I have a thread that returns a site's http response status, but sometimes my
how do I format output in seconds:milliseconds format? TimeSpan start = TimeSpan.Parse(pair.Value[3]); TimeSpan end
I need a TimeSpan that takes into account working hours. Let's say that if
I need to parse .net TimeSpan on jQuery, I'm trying through jQuery globalization but
I'm using a timespan function to work out the number of days, this value
How do you elegantly format a timespan to say example 1 hour 10 minutes
It appears that ConfigurationElement of TimeSpan can't handle values larger than 23:59:59. Are there

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.