title: In Blazor WebAssembly in a component, how can I make DateTime.ToString use the date format of the current culture, assuming the culture is correct?
body: <p>I have temporarily set my browser language and locale to English - United Kingdom even though I am in the United States.  I have removed &quot;en-US&quot; and now have &quot;en-GB&quot; as my only language preference.</p>
  <p>In my Blazor WebAssembly site, on a component, I have a property that returns a string: <code>myDate.ToString(&quot;d&quot;) + System.Globalization.CultureInfo.CurrentCulture.DisplayName;</code> that renders on my page as <code>6/27/2020en (GB)</code>, where myDate is a DateTime set to June 27, 2020 at 00:00:00.000.  My Blazor site has <code>app.UseRequestLocalization(...)</code> middleware set up.</p>
  <p>Isn't is supposed to show the date in UK format, namely <code>27/06/2020</code>? I can only guess that ShortDatePattern isn't getting properly set from CultureInfo.CurrentCulture.  What could it be?</p>
  <p>UPDATE: All WebAssembly component outputs show me that <code>DateTimeFormatInfo.CurrentInfo.ShortDatePattern == &quot;M/d/yyyy&quot;</code> even though <code>CultureInfo.CurrentCulture.Name == &quot;en-GB&quot;</code>.  Why might that be?  What sets ShortDatePattern from the culture and can I &quot;re-initialize&quot; it?</p>
  <p>An explicit call to <code>myDate.ToString(&quot;d&quot;, System.Globalization.CultureInfo.GetCultureInfo(&quot;en-GB&quot;));</code> still strangely outputs the <strong>M/d/yyyy</strong> format (U.S. format). <strong>Why might that be?</strong></p>
  <p>UPDATE 2:  I created a minimal example: File-New Project, Blazor Web Assembly, .NET 5 ASP.NET Core hosted.  I replaced App.Razor with the following:</p>
  <pre><code>&lt;div&gt; current culture @(System.Globalization.CultureInfo.CurrentCulture.Name) &lt;/div&gt;
  &lt;div&gt; current date format @(System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern) &lt;/div&gt;
  &lt;div&gt; today @DateTime.Now.ToString(&quot;d&quot;) &lt;/div&gt;
  </code></pre>
  <p>That results in (unexpectedly):</p>
  <p><a href="https://i.stack.imgur.com/P2YpY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P2YpY.png" alt="enter image description here" /></a></p>
  <p>Firefox browser settings (Edge and Chrome are similar and show the same issue):</p>
  <p><a href="https://i.stack.imgur.com/gnqJE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gnqJE.png" alt="enter image description here" /></a></p>
  <p>That results in sending <code>Accept-Language: en-GB,en-US;q=0.7,en;q=0.3</code>--which seems to be the correct way to &quot;prefer en-GB&quot; and results in CultureInfo.CurrentCulture having the correct value.</p>
  <p>I've tried it with Microsoft.AspNetCore.Components.WebAssembly.* nuget packages version 5.0.9, 5.0.11 - both show the same incorrect result.</p>
  <p>UPDATE 3: The same minimal project in 6.0.0-rc.1 works and gives the right date format!  <strong>Is this really a Blazor 5 bug that they never fixed?</strong></p>