2

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>

NinjaShawarma
  • 69
  • 1
  • 1
  • 9
  • It might just make sense to search the web for "javascript date format" or something similar, no? – Dave Newton Nov 14 '16 at 14:38
  • @DaveNewton I have tried, but it got me confused. :( – NinjaShawarma Nov 14 '16 at 14:39
  • here is the google link https://www.google.com/search?q=javascript%20change%20date%20format&rct=j – Kevin Kloet Nov 14 '16 at 14:40
  • But there are running examples on the web *and* on Stack Overflow. I'd recommend at least *trying* something before asking someone to do it for you, but maybe that's just me. In general SO is for specific problems as opposed to asking people to do all the work. – Dave Newton Nov 14 '16 at 14:40
  • There is an impressive amout and quality of documentation available for this API. http://bootstrap-table.wenzhixin.net.cn/documentation/ What have you found so far? – Igor Nov 14 '16 at 14:40
  • @DaveNewton Thanks for the advice. I did my research. Those are just small things that I'm stuck at of a bigger project. Sorry for bothering at all means. – NinjaShawarma Nov 14 '16 at 14:43
  • 1
    @Igor I've looked into the API but I couldn't find something useful. Thanks! I will dig deep. – NinjaShawarma Nov 14 '16 at 14:44
  • the same answer is here on stack overflow – zerohero Nov 14 '16 at 15:10
  • Possible duplicate of [How can I pretty-print JSON using JavaScript?](http://stackoverflow.com/questions/4810841/how-can-i-pretty-print-json-using-javascript) – zerohero Nov 14 '16 at 15:10

1 Answers1

9

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>
BEJGAM SHIVA PRASAD
  • 2,181
  • 1
  • 18
  • 27
  • This was a helpful answer for me, although moment.js is now (2023) considered a legacy project (https://momentjs.com/docs/). Instead, I used Luxon to format dates (https://moment.github.io/luxon/#/) – Martin Perrie Jul 15 '23 at 13:40