Json Date / Date Return (1519339100637) /

1

Good evening, I'm working with Ajax to return a json that contains a data in Datetime format but I'm getting string /Date(1519339100637)/ . How can I convert to date and time format 23/02/2018 12:00:00:

Ajax function:

<script type="text/javascript">
    function GetData(andamento_id) {
        var $tbl = $('#tbl');
        $.ajax({
            url: 'Andamento.aspx/GetComentarioAndamento',
            data: "{'AndamentoID':'" + andamento_id + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            type: "POST",
            success: function (data) {
                debugger;
                if (data.d.length > 0) {
                    for (var i = 0; i < data.d.length; i++) {
                        $tbl.append('<tr><td>' + data.d[i].ComentarioTexto
                            + '</td><td>' + data.d[i].DataHoraComentario
                            + '</td><td>'
                            + "<div class='row centered'><div class='user-block'><img src='"
                            + data.d[i].FotoProfile + "' data-toggle='tooltip' title='"
                            + data.d[i].NomeAdvogado + "' class='img-circle img-bordered-sm'></div></div>"
                            + '</td></tr>');
                    }
                }
            }
        });
    }
</script>

    
asked by anonymous 24.02.2018 / 00:13

1 answer

1

Create a new Date() object with only the numeric part of the expression, and use toLocaleString() to return the date in dd-mm-aaaa hh:mm:ss format. Here's what for would look like:

for (var i = 0; i < data.d.length; i++) {
   var d = new Date(Number(data.d[i].DataHoraComentario.match(/(\d)+/)[0])).toLocaleString();
   $tbl.append('<tr><td>' + data.d[i].ComentarioTexto
       + '</td><td>' + d
       + '</td><td>'
       + "<div class='row centered'><div class='user-block'><img src='"
       + data.d[i].FotoProfile + "' data-toggle='tooltip' title='"
       + data.d[i].NomeAdvogado + "' class='img-circle img-bordered-sm'></div></div>"
       + '</td></tr>');
}
    
24.02.2018 / 19:41