JQGrid 格式化日期返回错误的日期
我正在使用 JQGrid 来显示我的数据(服务器返回 xml)。数据似乎没问题:
<aux>
<sessao>181092</sessao>
<codFuncionario>13574</codFuncionario>
<dataMarcacao class="sql-date">2011-10-15</dataMarcacao>
<sequencia>1</sequencia>
<seqHe/>
<codPagamento/>
<seqOcorrencia>0</seqOcorrencia>
<tipoOcorrencia/>
<diaSemana>SAB</diaSemana>
</aux>
<aux>
<sessao>181092</sessao>
<codFuncionario>13574</codFuncionario>
<dataMarcacao class="sql-date">2011-10-16</dataMarcacao>
<sequencia>1</sequencia>
<seqHe/>
<codPagamento/>
<seqOcorrencia>0</seqOcorrencia>
<tipoOcorrencia/>
<diaSemana>DOM</diaSemana>
<inconsistencias>FALTA DIA</inconsistencias>
</aux>
在网格初始化时,我设置了格式:
colModel:[ {name: 'dataMarcacao',
index: 'dataMarcacao',
width: 60,
formatter: 'date',
formatoptions: {newformat: 'd/m/Y', datefmt: 'Y-m-d'}},
我不明白的是网格显示 15/10/2011 两次,而不是 16/10/2011。
我该如何调试这个?也许是 JQGrid 错误?
我也尝试过:
colModel:[ {name: 'dataMarcacao',
index: 'dataMarcacao',
width: 60,
formatter: 'date',
formatoptions: {newformat: 'Y-m-d', datefmt: 'Y-m-d'}},
这得到了同样的错误结果。
I'm using JQGrid to display my data (the server returns xml). The data seems to be OK:
<aux>
<sessao>181092</sessao>
<codFuncionario>13574</codFuncionario>
<dataMarcacao class="sql-date">2011-10-15</dataMarcacao>
<sequencia>1</sequencia>
<seqHe/>
<codPagamento/>
<seqOcorrencia>0</seqOcorrencia>
<tipoOcorrencia/>
<diaSemana>SAB</diaSemana>
</aux>
<aux>
<sessao>181092</sessao>
<codFuncionario>13574</codFuncionario>
<dataMarcacao class="sql-date">2011-10-16</dataMarcacao>
<sequencia>1</sequencia>
<seqHe/>
<codPagamento/>
<seqOcorrencia>0</seqOcorrencia>
<tipoOcorrencia/>
<diaSemana>DOM</diaSemana>
<inconsistencias>FALTA DIA</inconsistencias>
</aux>
On the init of the grid I setup the format:
colModel:[ {name: 'dataMarcacao',
index: 'dataMarcacao',
width: 60,
formatter: 'date',
formatoptions: {newformat: 'd/m/Y', datefmt: 'Y-m-d'}},
What I don't understand is that the grid shows 15/10/2011 twice, instead of 16/10/2011.
How can I debug this? Maybe JQGrid bug?
I also try:
colModel:[ {name: 'dataMarcacao',
index: 'dataMarcacao',
width: 60,
formatter: 'date',
formatoptions: {newformat: 'Y-m-d', datefmt: 'Y-m-d'}},
and this gets the same wrong result.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Sérgio Michels 在他自己的问题中回答了这个问题,我在下面清理了它:
这似乎是 PDT 的一个错误。 Firebug 显示了时间戳:
Date {Sat Oct 15 2011 00:00:00 GMT-0300 (Hora oficial do Brasil)}
日期 {Sat Oct 2011 年 15 月 23:00:00 GMT-0300(巴西官方时间)}
— 这应该是 10 月 16 日!日期 {2011 年 10 月 17 日星期一 00:00:00 GMT-0200}
我发现问题与SO和JavaScript对象
Date
有关。在 Windows 中,当您打开自动更新时钟时间的选项时,“日期”对象将返回您的日期减去夏令时一小时。为了解决这个问题,我在第 4667 行编辑了
jquery.jqGrid.src.js
:而不是
j = timestamp.getDate()
。Sérgio Michels answered this in his own question, I cleaned it up below:
This seems to be a bug with PDT. Firebug shown the timestamps:
Date {Sat Oct 15 2011 00:00:00 GMT-0300 (Hora oficial do Brasil)}
Date {Sat Oct 15 2011 23:00:00 GMT-0300 (Hora oficial do Brasil)}
— this should be Oct 16!Date {Mon Oct 17 2011 00:00:00 GMT-0200}
I found out that the problem is related to the SO and the JavaScript object
Date
. In Windows, when you turn on the option to automatically update your clock time, the object `Date return your date minus one hour in your daylight saving time.To fix this i edited
jquery.jqGrid.src.js
on line 4667:instead of
j = timestamp.getDate()
.在 grid.locale js 中将 userLocalTime 更改为 true。这将给出当地时区
In grid.locale js change the userLocalTime to true. This will give the local timezone