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
In my opinion
en-GB
is the correct setting forculture
anduiCulture
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 asMM/dd/yyyy
like this:I put the CultureInfo.InvariantCulture there so that there is no chance that the serialization will be affected by future changes in the
culture
anduiCulture
settings for the application.