Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I would personally format it in two parts: the non-am/pm part, and the am/pm part with ToLower:</p> <pre><code>string formatted = item.PostedOn.ToString("dddd, MMMM d, yyyy a\\t h:mm") + item.PostedOn.ToString("tt").ToLower(); </code></pre> <p>Another option (which I'll investigate in a sec) is to grab the current DateTimeFormatInfo, create a copy, and set the am/pm designators to the lower case version. Then use that format info for the normal formatting. You'd want to cache the DateTimeFormatInfo, obviously...</p> <p>EDIT: Despite my comment, I've written the caching bit anyway. It probably won't be <em>faster</em> than the code above (as it involves a lock and a dictionary lookup) but it does make the calling code simpler:</p> <pre><code>string formatted = item.PostedOn.ToString("dddd, MMMM d, yyyy a\\t h:mmtt", GetLowerCaseInfo()); </code></pre> <p>Here's a complete program to demonstrate:</p> <pre><code>using System; using System.Collections.Generic; using System.Globalization; public class Test { static void Main() { Console.WriteLine(DateTime.Now.ToString("dddd, MMMM d, yyyy a\\t h:mmtt", GetLowerCaseInfo()); } private static readonly Dictionary&lt;DateTimeFormatInfo,DateTimeFormatInfo&gt; cache = new Dictionary&lt;DateTimeFormatInfo,DateTimeFormatInfo&gt;(); private static object cacheLock = new object(); public static DateTimeFormatInfo GetLowerCaseInfo() { DateTimeFormatInfo current = CultureInfo.CurrentCulture.DateTimeFormat; lock (cacheLock) { DateTimeFormatInfo ret; if (!cache.TryGetValue(current, out ret)) { ret = (DateTimeFormatInfo) current.Clone(); ret.AMDesignator = ret.AMDesignator.ToLower(); ret.PMDesignator = ret.PMDesignator.ToLower(); cache[current] = ret; } return ret; } } } </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