Return Datetime Json /Date(1519339100637)/

Asked

Viewed 1,732 times

1

Good evening, I’m working with Ajax to return a json containing a data in the format Datetime but I’m getting in string format /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>

inserir a descrição da imagem aqui

  • It’s always noon, 12:00?

  • @dvd is not an example 00:00:00

  • I get it... the day and time are on the number.

  • And how is the C# that sends the JSON?

  • @dvd Worked perfectly thank you!

1 answer

1


Create an object new Date() only with the numerical part of the expression, and use toLocaleString() to return the date in the format dd-mm-aaaa hh:mm:ss. See how it would look for:

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>');
}

Browser other questions tagged

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