简体   繁体   中英

How do I format server side Jquery Datatable rendering date from a timestamp?

I am hoping someone has figured out the issue I am having. I have an ajax call to my MySQL database. I am using ColdFusion and jQuery datatables to display my fields. Everything works fine except when I try to format the date. I have tried to use <cfset> to format the date prior to the JavaScript and I have tried a number of other solutions found online. Below is my code.

$(document).ready(function() {
  var table = $('#TableData').dataTable({
    "bProcessing": true,
    "bStateSave": true,
    "bServerSide": true,
    "sAjaxSource": "MyCFMCall.cfm",
    "aoColumns": [{
        "sName": "ID",
        "sClass": "hidden"
      },
      {
        "sName": "DATABASE_DATE",
        "sTitle": "APP DATE",
        "bSortable": "true"
      } //<!---My timestamp from the database--->

    ],

    "columnDefs": [

      {
        "render": function(data, type, row) {
          return "+row[1]+";
        }, //<!---This will render the timestamp only, yet not formated.--->
        "targets": 1
      }
    ],
  });
});

If anyone can show me how to format this rendered timestamp into a more readable format I would really appreciate it.

you should look into moment.js for parsing the timestamp. maybe this answer would be of some help Convert Date from one format to another format in JavaScript

Also, if you could tell me what format is the date actually in when you recieve it from the server? and do look into the 2nd answer there to avoid using a library.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM