问题
I am using the jQuery JQGrid plug-in, version 3.8.2 and am having trouble trying to figure out how to format a date/time for display. The date/time comes in ISO long format, i.e. 2011-02-16T14:46:43Z. I want it shown in mm/dd/yy H:m:s format. Here is my current code, which does not work:
currOption.formatoptions = {
srcformat: 'Y-m-dQH:i:sZ',
newformat: 'm/d/Y g:i A'
};
Note that I have a "Q" in there because if I use "T", it blows up (which makes sense, as "T" has meaning in PHP date formatting).
Can anyone help me figure out how to properly do this formatting?
回答1:
Turns out that you have to leave out the "T" and "Z" to make it read the incoming date/times properly. This code works:
currOption.formatoptions = {
srcformat: 'Y-m-d H:i:s',
newformat: 'n/j/Y g:i A'
};
I hope this helps others who encounter the same problem!
回答2:
Have you tried this instead?
{srcformat: "ISO8601Long", newformat: 'd/m/Y H:i'}
回答3:
The jqGrid wiki says to use datefmt:'mm/dd/yyyy'. Have you tried that ?
来源:https://stackoverflow.com/questions/6747782/jqgrid-date-formatting