Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The strict answer to this question:</p> <blockquote> <p>Is there some way to do it apart from implementing it myself? I'm willing to use third-party libraries.</p> </blockquote> <p>Is no, unless a third party has done this already, you'll need to implement your own format string parser. </p> <p>I share the opinion of most respondents that the effort required to do that is utterly out of proportion to the alternative of simply memorizing the DateTime formats already provided (or referring to their documentation). But, if you did undertake such effort, you would want to implement an <a href="http://msdn.microsoft.com/en-us/library/system.icustomformatter.aspx" rel="nofollow">ICustomFormatter</a>, and an <a href="http://msdn.microsoft.com/en-us/library/system.iformatprovider.aspx" rel="nofollow">IFormatProvider</a> that would provide it when requested.</p> <p>See the ICustomFormatter documentation linked above for an example, but your task will involve providing a <code>Format(string format, object arg, IFormatProvider formatProvider)</code> method that takes a string in the format <em>you</em> are interested in and uses it to turn the DateTime passed in <code>arg</code> into a string matching that pattern.</p> <p>Once this is done, and you have an IFormatProvider whose <code>GetFormat()</code> method returns your custom formatter, your sample code would look like this:</p> <pre class="lang-cs prettyprint-override"><code>DateTime someDate = DateTime.Now; Console.WriteLine(someDate.ToString("Wed, June 12", new CustomDateFormatter())); </code></pre>
    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. 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.
 

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