title: How to set date formats and culture in asp.net core razor pages 2.2
body: <p>I'm using Asp.Net Core 2.2 Razor Pages application. I want to set application culture and date formats in application level. So after some googling I end up adding the below code in <code>ConfigureServices</code> method in <strong>Startup.cs</strong></p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
          {
              // setting the application culture to en-US with MM/dd/yyyy short date pattern.
              var culture = CultureInfo.CreateSpecificCulture("en-US");
              var dateformat = new DateTimeFormatInfo { ShortDatePattern = "MM/dd/yyyy", LongDatePattern = "MM/dd/yyyy hh:mm:ss tt" };
              culture.DateTimeFormat = dateformat;
              Thread.CurrentThread.CurrentCulture = culture;
              Thread.CurrentThread.CurrentUICulture = culture;
  </code></pre>
  
  <p>But this doesn't seem to work. I'm getting the date in wrong format. Example,
  <code>DateTime.Now.ToShortDateString()</code> returns <strong>6/25/2019</strong> instead of <strong>06/25/2019</strong>. The same is the problem with <code>DateTime.Now.ToLongDateString()</code></p>
  
  <p>And If I change the format to "dd/MM/yyyy" will it return the date in <strong>25/06/2019</strong>??</p>
  
  <p>I'm running this in my local development environment. Also what I'm expecting is that my app to get the dates in the same format I set above in any environment, any machine, any culture.</p>
  
  <p>Please assist and guide me on where I'm wrong.</p>
  
  <p>Thanks in advance!! </p>