javascriptdatetimejqgriddatetime-formatjqgrid-formatter

jgGrid Showing wrong Time in DateTime field


I am using jqGrid in one of my application. In this I have show the date in this d/m/Y H:m:s(Ex 01/12/2011 14:59:10). I am getting format correctly but it show wrong time (at minutes) like : I am getting date time form database is 01/12/2011 14:59:10 but it showing 01/12/2011 14:12:10.

this is the jqGrid code:

url: "/DigitalJobMonitoring/GetFailedGridData",
datatype: 'json',
mtype: 'Get',
colNames: ['Sr.No', 'Job Name', 'Server Name', 'Status', 'Last Run Time'],
colModel: [
    { key: true, width: 50, resizable: false, name: 'SerialNumber', index: 'SerialNumber', sorttype: 'integer' },
    { key: false, width: 300, resizable: false, name: 'JobName', index: 'JobName', sorttype: 'text' },
    { key: false, width: 100, resizable: false, name: 'ServerName', index: 'ServerName', sorttype: 'text' },
    { key: false, width: 100, resizable: false, name: 'Status', index: 'Status', sorttype: 'text' },
    { key: false, width: 150, resizable: false, name: 'LastRunTime', index: 'LastRunTime', sorttype: 'date', formatter: 'date', formatoptions: { srcformat: "d/m/Y H:m:s", newformat: "d/m/Y H:m:s" }, searchoptions: { dataInit: initDateSearch } }],
search: true,
searchOnEnter: true,
pager: '#failedRunningPager',
height: '100%',
caption: 'Failed/Running Jobs',
emptyrecords: 'No records to display',
jsonReader: {
    root: "rows",
    page: "page",
    total: "total",
    records: "records",
    repeatitems: false,
    SerialNumber: "0"
},

I have tried with different srcformat(ISO8601Long,UniversalSortableDateTime,d/m/Y H:m:s,SortableDateTime etc.) in formatoptions but no luck. find screenshots here. date time from data base:

date time from data base

thanks in advance

Updated :

Here is the JSON date which returned to server


Solution

  • The Microsoft Date format /Date(1485158400000)/ will be automatically detected by recent versions of jqGrid. I recommend you uninstall NuGet package jQuery.jqGrid 4.4.4 and install free-jqGrid 4.13.6. jqGrid 4.4.4 is very old (4 years old) and it's deprecated since many years.

    The demo https://jsfiddle.net/OlegKi/9mz4q1gd/1/ uses free-jqGrid 4.13.6 and the following properties in colModel

    sorttype: "date", formatter: "date", formatoptions: { newformat: "d/m/Y H:m:s" }
    

    You can see that the dates will be correctly parsed, formatted and sorted in both input formats: ISO8601 and Microsoft Date.

    UPDATED: I see finally your error. You used wrong format for the minutes in the date format. You used month instead of minutes. You should fix newformat: "d/m/Y H:m:s" to newformat: "d/m/Y H:i:s". See: https://jsfiddle.net/OlegKi/u5Lvepyu/14/