问题
I'm having trouble figuring out where I'm going wrong with this date formatting on jqGrid. I pass in the date formatted by C# as MM/dd/yyyy hh:mm:ss tt
which produces 01/20/2012 10:01:26 PM
.
In my jqGrid I apply formatting as follows:
colModel: [
...
{ name: 'EndTime', index: 'EndTime', sorttype: 'date', formatter:'date', formatoptions: {srcformat:'m/d/Y h:i:s A', newformat:'m/d/Y h:i:s A'} },
...
],
This is working fine for everything except the AM/PM. It's always showing AM in my grid. From jqGrid's documentation, it looks like this should be the right format. Does anyone see where I'm going wrong?
Thanks!
回答1:
I found a solution. I changed the formatting in C# to yyyy-MM-dd HH:mm:ss
and my colModel to formatoptions: { srcformat: 'Y-m-d H:i:s', newformat: 'm/d/Y h:i:s A' }
.
The source format is the ISO8601Long format. I did not use 'ISO8601Long' since I'm using local data and want to sort.
来源:https://stackoverflow.com/questions/9203678/am-pm-date-formatting-in-jqgrid