0

I am working on asp.net mvc2 application. Problem is that when i am displaying date in format MM/dd/yyyy application work, but i must display the date in format dd/MM/yyyy to user. I set date in this format, but then i have problem with web service because it expect date format in MM/dd/yyyy, and i always get an error.

First i thought to write simple method that would convert date from one format to another ,and display in dd/MM/yyyy . But i have to match methods that use date, and i will have to make changes at many places.

I tried to use globalization in web config file like

​    <system.web>
​​        <globalization 
             requestEncoding="utf-8"
             responseEncoding="utf-8"
             culture="en-GB"
             uiCulture="en-GB" 
        />
    </system.web>

But that did not work for me. Is there some way to change date format when i display to the user, and then web service can accept it?

Thanks

  • Does this help: http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx – Marthijn Nov 14 '14 at 08:23
  • Its MM (month) not mm (minutes). Setting the culture on the server should be fine, or you can create a custom model binder [Refer example here](http://stackoverflow.com/questions/26813345/wrong-dateformat-with-jquery-datepicker/26813682#26813682) –  Nov 14 '14 at 08:28

1 Answers1

0

In my opinion en-GB is the correct setting for culture and uiCulture since this is the culture which has the date format you want to show to the user: dd/MM/yyyy

In those places where you are calling an API which requires the MM/dd/yyyy you should specify the format explicitly as MM/dd/yyyy like this:

myDate.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture);

I put the CultureInfo.InvariantCulture there so that there is no chance that the serialization will be affected by future changes in the culture and uiCulture settings for the application.

Svein Fidjestøl
  • 3,106
  • 2
  • 24
  • 40