Vipul Malani
Vipul Malani

Reputation: 21

In JqGrid Display Date Time../Date(1352658600000)/

/Date(1352658600000)/ 

When Display the date Date is not Display in Proper Format.

How to convert in to proper Format(dd/mm/yyyy)?

Upvotes: 2

Views: 7433

Answers (2)

tpeczek
tpeczek

Reputation: 24125

All you need to make the conversion is setting date formatter in jqGrid colum model:

$('#gridId').jqGrid({
    ...
    colModel: [
        ...
        { name: 'Column Name', index: 'Column Index', ..., formatter: "date", formatoptions: { newformat: "m/d/Y"} },
        ...
    ],
    ...
});

For the newformat option jqGrid supports PHP date formatting.

Upvotes: 7

SimonGates
SimonGates

Reputation: 6111

Taken from the accepted answer here - Converting json results to a date

You need to extract the number from the string, and pass it into the Date constructor:

var x = [ {"id":1,"start":"\/Date(1238540400000)\/"}, {"id":2,"start":"\/Date(1238626800000)\/"} ];

var myDate = new Date(x[0].start.match(/\d+/)[0] * 1));

The parts are:

x[0].start                                - get the string from the JSON
x[0].start.match(/\d+/)[0]                - extract the numeric part
x[0].start.match(/\d+/)[0] * 1            - convert it to a numeric type
new Date(x[0].start.match(/\d+/)[0] * 1)) - Create a date object

Upvotes: 1

Related Questions