Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In jqGrid, how to format timestamp to dd/mm/yyyy format

Tags:

jqgrid

My application send timestamp data to jqgrid (like "1268913728759").

now i want to format it like dd/mm/yyyy.

In jqGrid I added following line but it doesn't worked

{name:'testDate',index:'testDate', width:100, formatter:'date', formatoptions: {srcformat: 'ts',newformat:'d/m/Y'}}
like image 613
Romani Avatar asked Nov 21 '11 12:11

Romani


2 Answers

The correct seetings for this case should be like this:

formatter:'date', formatoptions: {srcformat: 'U', newformat:'d/m/Y'}

The 'U' is format character for 'Seconds since the Unix Epoch' date format.

like image 174
tpeczek Avatar answered Oct 31 '22 16:10

tpeczek


Try this:

formatter: function (cellValue, opts, rwd) {
    if (cellValue) {
        return $.fn.fmatter.call(this, "date", new Date(cellValue), opts, rwd);
    } else {
        return '';
    }
}

The correct seetings for this case should be like this:

formatter:'date', formatoptions: {srcformat: 'U', newformat:'d/m/Y'}

The 'U' is format character for 'Seconds since the Unix Epoch' date format.

The timestamp like "1268913728759" means milliseconds not seconds since the Unix Epoch

like image 41
Muyutu Avatar answered Oct 31 '22 17:10

Muyutu