Search code examples
javascriptjsonbootstrap-table

How do you convert dates in JSON/Bootstrap-Table to DD/MM/YYYY


I want to format 2016-09-14T13:46:39+0000 to DD/MM/YYYY. The data is coming from a JSON file/url into a bootstrap-table. Is there a way to format this using bootstrap-table or javascript?

See jsfiddle

Thanks,

<table data-toggle="table" 
   data-url="https://api.myjson.com/bins/44564"
   data-row-style="rowStyle">
<thead>
<tr>
    <th data-field="createdAt">Created At</th>
</tr>
</thead>


Solution

  • Check this will resolve your issue.. Am using moment js to format data.. ..

    function dateFormat(value, row, index) {
       return moment(value).format('DD/MM/YYYY');
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://momentjs.com/downloads/moment.min.js"></script>
    <script src="https://rawgit.com/wenzhixin/bootstrap-table/master/src/bootstrap-table.js"></script>
    <link href="https://rawgit.com/wenzhixin/bootstrap-table/master/src/bootstrap-table.css" rel="stylesheet"/>
    
    <table data-toggle="table" 
           data-url="https://api.myjson.com/bins/44564"
           data-row-style="rowStyle">
        <thead>
        <tr>
            <th data-field="createdAt" data-formatter="dateFormat">Created At</th>
        </tr>
        </thead>
    </table>