Problems with date format

Asked

Viewed 217 times

3

I am developing a system using C# MVC and Jquery UI and at the moment I am having problems with date formats, in inputs is the date in the correct format "dd/mm/yyyy" but the server is receiving the date in the format "mm/dd/yyyy".

Apparently the Culture of the web.config that is correct:

<globalization culture="pt-BR" uiCulture="pt-BR" enableClientBasedCulture="true"  requestEncoding="utf-8"/>

The Datepicker also seems to be in the correct format, as it is showing all the information of the months in Portuguese and when I select a date comes in the correct format.

  • Just remember that this tag applies server-side formatting. Have you explicitly defined somewhere that Datepicker uses the dd/mm/yyyy format? Tested using a date > 12 (30/10/2014)?

2 answers

2

0

Friend you can as much as convert it using javascript, from the current format to the form of the server.

  function converterData(dataString){
       split = dataString.split('/');
      return novadata = split[1] + "/" +split[0]+"/"+split[2];

    } 

or with C# (from the jquery server)

class Program
{
    static String Main(){
       string str = "11/30/2014";
       string[] data = str.Split('/');
       return data[1] + "/" + data[0] + "/" +data[2];  
    }
}
  • 1

    These transformations should be transparent, not dependent on string manipulator functions created by the programmer. That’s why we have Globalization libraries, so native of . NET (as quoted by the author of the question), as quoted in the answer given by the Roma.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.