Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What's going on is that <code>TimeSpan.Parse</code> attempts to parse <code>##:##:##</code> using each of the following formats in order, stopping as soon as one succeeds:</p> <ol> <li><code>hh:mm:ss</code> (invariant culture)</li> <li><code>d.hh:mm</code> (invariant culture)</li> <li><code>hh:mm:ss</code> (localized)</li> <li><code>d.hh:mm</code> (localized; more details about the "." below)</li> </ol> <p>So:</p> <ul> <li><code>23:08:09</code> is successfully parsed as 0d 23h 8m 9s in Step 1.</li> <li><code>24:08:09</code> is successfully parsed as 24d 8h 9m 0s in Step 4.</li> </ul> <p>If this behavior doesn't suit you, you can use <a href="http://msdn.microsoft.com/en-us/library/dd992370.aspx">TimeSpan.ParseExact</a> instead:</p> <pre><code>TimeSpan.ParseExact("23:00:00", "hh':'mm':'ss", null) // OK TimeSpan.ParseExact("24:00:00", "hh':'mm':'ss", null) // OverflowException </code></pre> <p><strong>UPDATE:</strong> According to the documentation for <a href="http://msdn.microsoft.com/en-us/library/se73z7b9.aspx">TimeSpan.Parse</a>, the "." between "d" and "hh" is</p> <blockquote> <p>A culture-sensitive symbol that separates days from hours. The invariant format uses a period (".") character.</p> </blockquote> <p>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 <code>DateTimeFormatInfo.FullTimeSpanPositivePattern</code> property:</p> <pre><code>string separator = new NumberFormatInfo(cultureData).NumberDecimalSeparator; this.m_fullTimeSpanPositivePattern = "d':'h':'mm':'ss'" + separator + "'FFFFFFF"; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload