简体   繁体   中英

How to change this date format in jqgrid

I am trying to print the following dates with the format 'dd-mm-yy' in a Jquerygrid.

Date a) 2017-01-05 00:00:00.0 CST
Date b) 2016-09-02 00:00:00.0

JqueryGrid Field:

        name : 'birthDate',
        index : 'birthDate',
        xmlmap : 'birthDate',
        sorttype : 'date',
        formatter : 'date',
      //current  fail attempt:
        formatoptions: { srcformat: "ISO8601Long", newformat: "d/m/Y" }, 
        width : 130,
        resizable : true

But the above does not work with any of the following masks:

     ISO8601Long:"Y-m-d H:i:s",
     ISO8601Short:"Y-m-d",
     ShortDate: "n/j/Y",
     LongDate: "l, F d, Y",
     FullDateTime: "l, F d, Y g:i:s A",
     MonthDay: "F d",
     ShortTime: "g:i A",
     LongTime: "g:i:s A",
     SortableDateTime: "Y-m-d\\TH:i:s",
     UniversalSortableDateTime: "Y-m-d H:i:sO"

The field is printed as if no mask was applied.

Should I use a pattern to print the date in the "dd-mm-yyyy" format? or what mask could be used to print the date?

You should try this:

formatter: dateFormatter,

function dateFormatter(cellValue, options, rowObject){
if(cellValue){
    var d = new Date(cellValue);
    var day = d.getDate();
    var month = d.getMonth() + 1;
    var year = d.getFullYear();
    if (day < 10) {
        day = "0" + day;
    }
    if (month < 10) {
        month = "0" + month;
    }
    var date = day + "-" + month + "-" + year;
    return date;
}
return "";
}

您可以尝试: 演示

formatoptions: { srcformat: "ISO8601Long", newformat: "d-m-Y" }, 

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