1

I have a jQuery table with a column containing dates in milliseconds format. I would like to convert from milliseconds to mm/dd/yyyy. I haven't been able to figure out how to convert the date value and integrate it into my script.

Please check out my fiddle and offer any advice you may have: http://jsfiddle.net/tommy6s/eLbq2wvh/

$(document).ready(function() {
    $.getJSON("http://www.corsproxy.com/dvl.thomascooper.com/data/json_return.json", function(data) {
        //static table head
        $('table.stats').append("<th>" + "</th>" + "<th>" + "Date" + "</th>" + "<th>" + "Brand" + "</th>" + "<th>" + "Author" + "</th>" + "<th>" + "Title" + "</th>" + "<th>" + "Posts" + "</th>" + "<th>" + "Exposure" + "</th>" + "<th>" + "Engagement" + "</th>");
        //loop through json data
        $.each(data.data.rows, function(i, val) {
            //+1 to number each row starting at 1
            var rowNum = i + 1;
            //create table rows and cell and populate with data 
            $('table.stats').append("<tr>" + "<td>" + rowNum + "</td>" + "<td>" + val[0].value + "</td>" + "<td>" + val[1].value + "</td>" + "<td>" + val[2] + "</td>" + "<td>" + val[3].label + "</td>" + "<td>" + val[4].values[0] + "</td>" + "<td>" + val[5].values[0] + "</td>" + "<td>" + val[6].values[0] + "</td>" + "</tr>");

        });
    });
});
Colin Brock
  • 21,267
  • 9
  • 46
  • 61
t6s
  • 81
  • 2
  • 14

1 Answers1

0

You can use :

new Date(val[0].value).toLocaleFormat('%m/%d/%Y')

instead of val[0].value .

Refer to this.

Lrrr
  • 4,755
  • 5
  • 41
  • 63
Ritesh Ranjan
  • 16
  • 1
  • 1
  • "This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future." – callback Nov 06 '16 at 22:21