Home > Back-end >  How do I fix Date Format
How do I fix Date Format

Time:11-28

I get this date format when importing file on my table /Date(1669623082703)/ I want to display it as yyyy-MM-dd HH:mm.

This is my table:

<table id="FileTable" >
<thead>
    <tr>
        <th>File ID</th>
        <th>Uploader ID</th>
        <th>File Name</th>
        <th>Program</th>
        <th>Date</th>          
    </tr>

</thead>


</table>

<script>
    $(document).ready(function () {

        $("#FileTable").DataTable({

            "ajax": {
                "url": "/Student/GetExcelList",
                "type": "GET",
                "datatype": "json"
            },
            "columns": [

                { "data": "FileID" },
                { "data": "UserIDUp" },
                { "data": "FileName" },
                { "data": "TakerProgram" },
                { "data": "DateUp" },                  

            ]

        });

    });
 </script>

This is what I am trying to do in my DateTime in the model folder:

    [DisplayFormat(ApplyFormatInEditMode =true, DataFormatString ="{0:yyyy-MM-d- 
    HH:mm}")]
    public System.DateTime? DateUp { get; set; }


    }

https://i.stack.imgur.com/VGkAY.png

CodePudding user response:

You can render the data in the AJAX call to be in the format you need.

Try perform the following:

    {
        data: 'DateUp',
        render: function (data, type, row) {
            if (type == "sort") return data;
            return moment(row.DateUp).format('YYYY-MM-DD HH:mm');
        }
     }
  • Related