Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Please note: this answer is for .Net 4.0 and above. If you want to format a TimeSpan in .Net 3.5 or below please see <a href="https://stackoverflow.com/a/574894/39277">JohannesH's answer</a>.</strong></p> <p>Custom TimeSpan format strings were introduced in .Net 4.0. You can find a full reference of available format specifiers at the MSDN <a href="http://msdn.microsoft.com/en-us/library/ee372287.aspx" rel="noreferrer">Custom TimeSpan Format Strings</a> page.</p> <p>Here's an example timespan format string:</p> <pre><code>string.Format("{0:hh\\:mm\\:ss}", myTimeSpan); //example output 15:36:15 </code></pre> <p>(<strong>UPDATE</strong>) and here is an example using C# 6 string interpolation:</p> <pre><code>$"{myTimeSpan:hh\\:mm\\:ss}"; //example output 15:36:15 </code></pre> <p>You need to escape the ":" character with a "\" (which itself must be escaped unless you're using a verbatim string).</p> <p>This excerpt from the MSDN <a href="http://msdn.microsoft.com/en-us/library/ee372287.aspx" rel="noreferrer">Custom TimeSpan Format Strings</a> page explains about escaping the ":" and "." characters in a format string:</p> <blockquote> <p>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.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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