0

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?

Kelvin Bongers
  • 187
  • 2
  • 12

2 Answers2

3

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)

Community
  • 1
  • 1
webdeveloper
  • 17,174
  • 3
  • 48
  • 47
0

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.

Roy Scheefhals
  • 111
  • 1
  • 5
  • This only seems to change the output, not the input. – Kelvin Bongers Nov 29 '12 at 11:01
  • I think you should then look to the jquery-ui datepicker to pick a date in a specific format. Or maybe you should pick the time, minutes, seconds and data as seperate data and construct your custom datetime format. Not sure how that has to be done in jquery, but that might be the case – Roy Scheefhals Nov 29 '12 at 11:24
  • I ended up doing that in fact, because I needed the Dutch format. But that still doesn't fix the initial problem that it changes what format it uses. – Kelvin Bongers Nov 29 '12 at 11:56