How to set culture to change datetime format in ASP.NET MVC
By FoxLearn 2/18/2024 1:28:07 AM 55
In this tutorial, I'll show you how to fix String was not recognized as a valid DateTime 'dd/MM/yyyy'
- The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
Open the web.config file, then add the configuration to set the uiculture and culture attributes as shown below.
<system.web> <globalization culture="en-US" uiCulture="en"/> </system.web>
or you can open Global.asax file then add the Application_BeginRequest as shown below
protected void Application_BeginRequest(Object sender, EventArgs e) { CultureInfo cultureInfo = (CultureInfo)Thread.CurrentThread.CurrentCulture.Clone(); cultureInfo.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy"; cultureInfo.DateTimeFormat.DateSeparator = "/"; Thread.CurrentThread.CurrentCulture = cultureInfo; }
We will clone the current culture, then modify our culture. The CultureInfo class provides information about a specific culture. It includes the names for the culture, the writing system, the calendar used, the sort order of strings and formatting for dates and numbers.
- How to fix "InvalidOperationException: No service for type 'Microsoft.AspNetCore.Identity.UserManager'"
- How to fix 'IMvcBuilder' does not contain a definition for 'AddNewtonsoftJson'
- ASP.NET Core: How to Create RDLC Report in ASP.NET Core
- ASP.NET MVC: Free Responsive Templates
- How to fix Assets file 'project.assets.json' not found
- How to fix 'DbContextOptionsBuilder' does not contain a definition for 'UseSqlServer'
- How to set cookie ValidationInterval in ASP.NET Core
- How to fix LoginPath not working in ASP.NET Core
Categories
Popular Posts
Visual Studio: Auto increment version
04/01/2024
What is ARM architecture?
04/01/2024