Kelvin Bongers
Kelvin Bongers

Reputation: 197

How to lock localization of DateTime in ASP.NET MCV4 C#

I'm working with a group on a project that at one point requires a DateTime to be posted in a form. We added a simple jquery-ui datepicker to do that, and it worked fine on my English configured machine. However when they tried using it themselves on a Dutch configured machine, the DateTime started using a different format, while the datepicker kept the same English format, causing errors.

How do I lock the DateTime localization in MVC4 (or the overall localization) to English to fix this? Alternatively, how do I detect the localization to make the datepicker use the different one?

Upvotes: 0

Views: 1935

Answers (2)

webdeveloper
webdeveloper

Reputation: 17288

Try this:

<globalization culture="en-US" uiCulture="en-US" />
  1. How to configure invariant culture in ASP.NET globalization?
  2. How to Set default language in web.config file ?

This will also fix potential problems with float's and etc (point vs comma)

Upvotes: 3

Roy Scheefhals
Roy Scheefhals

Reputation: 111

You could use a DataAnnotation to your DateTime object

[DisplayFormat(DataFormatString = "{0:dd-MM-yyyy HH:mm}")]
public DateTime dateTime;

then edit your format string to the English standard. If i am correct, it will always use this format.

Upvotes: 0

Related Questions