JQGrid 格式化日期返回错误的日期

发布于 2024-12-12 05:40:55 字数 1477 浏览 0 评论 0原文

我正在使用 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技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暗藏城府 2024-12-19 05:40:55

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.getUTCDate()

而不是 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:

j = timestamp.getUTCDate()

instead of j = timestamp.getDate().

分開簡單 2024-12-19 05:40:55

在 grid.locale js 中将 userLocalTime 更改为 true。这将给出当地时区

In grid.locale js change the userLocalTime to true. This will give the local timezone

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文