Change date format in ASP.NET MVC application

前端 未结 4 1678
孤街浪徒
孤街浪徒 2020-12-29 08:18

I need to change date format to be dd.MM.yyyy. I am getting client side validation error because ASP.NET MVC date format is different from what I expect on the

4条回答
  •  不思量自难忘°
    2020-12-29 09:03

    You can change the current culture in your Global.asax file, for application level For Example,

    using System.Globalization;
    using System.Threading;
    
    protected void Application_BeginRequest(Object sender, EventArgs e)
    {    
      CultureInfo newCulture = (CultureInfo) System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
      newCulture.DateTimeFormat.ShortDatePattern = "dd-MMM-yyyy";
      newCulture.DateTimeFormat.DateSeparator = "-";
      Thread.CurrentThread.CurrentCulture = newCulture;
    }
    

提交回复
热议问题