0

i have written a get api and i want to show some records in data table, while im getting records in json im getting date values like this "/Date(1498849454000)/". How to get date value in "2017-04-11 02:09" in this format. data is stored correctly "2017-04-11 02:09:17.000". data type - datetime

sample data

{"data":[{"updtd_date":"\/Date(1498849454000)\/","usecase":"watertank","id":1026,"sms":"Alert: Tank is Full  at 01/07/2017 12:33:51 AM ]"},

code

     <script>
            $(document).ready(function () {
                $('#myTable').DataTable({
                    "ajax": {
                        "url": "url",
                        "type": "GET",
                        "datatype": "json"
                    },
                    "columns" : [
                        { "data": "updtd_date", "autoWidth": true },
                        { "data": "usecase", "autoWidth": true },
                        { "data": "id", "autoWidth": true },
                        { "data": "sms", "autoWidth": true }
                        ]
                });
            });
        </script>

        <table id="myTable">
                <thead>
                    <tr>
                        <th>Time</th>
                        <th>Use Case</th>
                        <th>Sl no</th>
                        <th>SMS</th>
                    </tr>
                </thead>
            </table>

controller

   public ActionResult getSMS()
        {
            using (smartpondEntities dc = new smartpondEntities())
            {
                var data = dc.sms.OrderByDescending(a => a.id).ToList();
                return Json(new { data = data }, JsonRequestBehavior.AllowGet);
            }

        }
H77
  • 5,859
  • 2
  • 26
  • 39
pvkm
  • 19
  • 2
  • 9

2 Answers2

0

You can create a date object by passing your time in milliseconds as the parameter to the Date constructor var date = Date(1498849454000);

Then you can get the date by using date.toDateString()

Kartik Chauhan
  • 2,779
  • 5
  • 28
  • 39
0

if your date is displayed as Date(1498849454000) then it is a time stamp

$timestamp = //assign your date here after json decode
$timestamp = preg_replace( '/[^0-9]/', '', $timestamp);
$date = date("Y-m-d H:i:s", $timestamp / 1000);

this will transform timestamp (divided by 1000 cause of JS date) to a human-readable format. hope this helps.

Regolith
  • 2,944
  • 9
  • 33
  • 50