Reputation: 65
I need to display date from controller to view through jQuery in MVC4 razor.But it just displaying correctly.
To display date I used the below code:
$.each(data, function (index, el) {
console.log(el);
for (i = 0 ; i <el.length; i++) {
tr = $('<tr class="eachitem" />');
td = $('<td>' + el[i]["ID"] + '</td>').appendTo(tr);
td1 = $('<td>' + el[i]["Date"] + '</td>').appendTo(tr);
td1 = $('<td>' + el[i]["status"] + '</td>').appendTo(tr);
tr.appendTo('table');
}
});
Upvotes: 3
Views: 813
Reputation: 15609
I can recommend using Moment.js to parse, manipulate and display dates. It takes the pain out of something quite difficult in JavaScript
Upvotes: 0
Reputation: 1298
You need to parse the date string to a valid JavaScript date format. In order to do this use the following snippet from the answer in this question
var date = new Date(parseInt(value.replace("/Date(", "").replace(")/",""), 10));
After that, you will have a proper JavaScript date object which you can print in the format of your choice:
var stringDate = value.toLocaleString()
var stringDate = value.toISOString()
Upvotes: 1