JQGrid Date Formatting

拟墨画扇 提交于 2019-12-12 13:36:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!