Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can achieve that by instantiating the CultureInfo of your choice and pass that as a parameter to formatting functions (such as ToString). Just don't assign it to Thread.CurrentThread.CurrentCulture or Thread.CurrentThread.CurrentUICulture, since that will change the culture for the application as such.</p> <p>In your code:</p> <pre><code>CultureInfo myCulture = CultureInfo.GetCultureInfo("en-US"); Console.WriteLine(DateTime.Now.ToString(myCulture)); </code></pre> <p>If your code executes external code, and you want to force this code to use your internally chosen culture, you can do that by creating a new thread, assign the culture to that thread and then have that thread execute the code. Just make sure to pay attention to the threading issues that comes with that approach.</p> <p>Thread sample:</p> <pre><code>string formattedDate = string.Empty; Thread t = new Thread(delegate() { // call external code without specifying culture formattedDate = DateTime.Now.ToString(); waitHandle.Set(); }); t.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); t.Start(); waitHandle.WaitOne(); // wait for the thread to finish Console.WriteLine(formattedDate); </code></pre> <p>As a last point; I don't know <em>why</em> you want to override the CurrentCulture, but I would suggest that you think twice before doing so. Users are used to seeing dates an numbers formatted according to their locale; changing that could be confusing, especially if it happens in just one part of the UI.</p>
 

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