Format date dd / mm / yyyy in a jquery DataTable.net

1

How do I format this date 2016-10-23T20: 30: 01.017 in a Datatable.net in the Brazilian dd / mm / yyyy format?

Controller:

This relevant snippet of code is where I populate the object that is in the format ok: dd / mm / yyyy hh: mm: ss:

List<Cliente> lTotalClienteAux = _IRepositorio.ListarCliente().ToList();

                List<Cliente> lTotalCliente = new List<Cliente>();
                foreach (var item in lTotalClienteAux)
                {
                    Cliente oCliente = new Cliente();
                    oCliente.ClienteID = item.ClienteID;
                    oCliente.DataCadastro = item.DataCadastro;                       
                    lTotalCliente.Add(oCliente);
                }

View When you click here in the View the format changes to: 2016-10-24T20: 35: 13.617

{
      "mRender": function (data, type, full) {
      var dt = full['DataCadastro'];
      return '<td>' + dt + '</td>';
     }
},

web.config In web.config I have this tag indicating the culture:

<system.web>
    <globalization uiCulture="pt-BR" culture="pt-BR" enableClientBasedCulture="true" />
    
asked by anonymous 24.10.2016 / 17:48

2 answers

2

You can do it that way.

var data = new Date("2016-10-23T20:30:01.017");
var dia = data.getDate();
var mes = data.getMonth();
var ano = data.getFullYear();

document.write(dia + '/' + mes + '/' + ano);

Return

23/10/2016
    
24.10.2016 / 18:08
1

Serialize the data to Datatable.net already in the correct format instead of using javascript to format the date. Deliver the dice ready.

In this line: oCliente.DataCadastro = item.DataCadastro;

You should do: oCliente.DataCadastro = item.DataCadastro.ToShortDateString();

The DataCadastro property of the Client class must be a string. If Client was a domain object, you should create a view model for your screen, in this case ClientViewModel and in that view model, DataCadastro will be a string.

    
24.10.2016 / 17:51