I have a DataTable that's populated by axios get request data, and it includes times that used to be properly converted with help from moment.js. My code was working when I was using a local JSON file, but ever since switching to a url I've had to do a lot of code rewriting.
In the console the data comes up as date-times with the format YYYY-DD-MMThh:mm:ss, but when they're rendered to the browser they display as 01/01/1970 automatically. I figured that it might have to do with the code I was using earlier.
How can I rewrite my function so that it does render YYYY-DD-MMThh:mm:ss appropriately, preferably to MM/DD/YYYY?
JS snippet:
loadAdmData(response) {
let admissText = response.map(function(val) {
return {
"Date of Adm": val.DateofAdm,
"Expires": val.Expires
}
})
$('#admissions-table').DataTable({
columns: [
... // ---- irrelevant data
...
...
{ data: "Date of Adm" },
{ data: "Expires" }
],
columnDefs: [
{"type":"unix","targets":3,"render": function(data) {
return moment.utc(data, "x").format('MM/DD/YYYY')
}} // targets must be plural
],
...etc
Object snippet (console):
DateofAdm"1994-03-02T05:00:00Z"