JQGrid日期格式化程序未正确应用本地时间偏移量:Grails [英] JQGrid date formatter not applying local time offset correctly : Grails
问题描述
在jqgrid中,我有以下单元格定义:
{name:'processedDate',width:110,formatter:'date',formatoptions:{srcformat:'Ym-dTH:i: sZ',newformat:'d / m / YH:i'}}
在屏幕上看到的是
31/03/2013 22:06 这是什么显示在mysqlworkbench
中,我从另一个grails gsp函数获得
$ b
< g:formatDate format =dd / MM / yyyy HH:mmdate =$ {emailAudit.pollDate}/>
但是jqgrid单元格显示
31/03/2013 21:06
我今天已经注意到了,因为我们已经进入夏令时,所以这是一个小时。
来自grails控制器的JSON日期是
2013-03-31T21:06:45Z
(再次似乎缺少小时,但是当注销它时现在,由于在gsp formatdate函数中,所以应用本地偏移量似乎与mysqlworkbench的情况相同。
在grails中创建JSON以解决方案是手动应用偏移量的方法,如果有的话,最好的方式是做什么或在JQGrid中缺少哪些格式化选项?
使用其他人类似的解决方案(从stackoverflow显然)排序。我刚刚在引导程序中创建了一个对象编组器来处理日期。它的肮脏,并没有感觉到100%但它的工作(并涵盖所有的日期到JSON区域在我的代码),并将要做的现在。任何其他建议是受欢迎的,但我相信有一个比这更好的方法。
import grails.converters.JSON;
class BootStrap {
def init = {servletContext - >
JSON.registerObjectMarshaller(Date){
TimeZone tz = TimeZone.getDefault();
def dateFormat ='yyyy / MM / dd HH:mm'
return it?.format(dateFormat,tz)
}
I have a simple table in the DB (MySql) which contains the date in the standard Date format. I am doing a simple select in grails and rendering the output to a JSON format for the jqgrid to pick up.
In jqgrid I have the following cell definition:
{name : 'processedDate',width:110,formatter:'date', formatoptions: {srcformat: 'Y-m-dTH:i:sZ',newformat:'d/m/Y H:i'}}
The date I expect to see on the screen is 31/03/2013 22:06 which is what is displayed in the mysqlworkbench which I get from another grails gsp function
<g:formatDate format="dd/MM/yyyy HH:mm" date="${emailAudit.pollDate}"/>
but the jqgrid cell displays 31/03/2013 21:06
I have only noticed this today as we have gone into daylight savings time so it's an hour out.
The JSON date coming from the the grails controller is 2013-03-31T21:06:45Z (again seems to be missing the hour but when logged out its obviously converted by grails somehow).
Now since in the gsp formatdate function it's applying local offset as seems to be the case with the mysqlworkbench.
Is the solution when creating the JSON in grails to apply the offset manually and if so whats the best way to do this or is there something in the formatting options in JQGrid that I am missing?
Sorted it using other peoples similar solutions(from stackoverflow obviously). I just created a object marshaller in the bootstrap to deal with dates. Its dirty and doesnt feel 100% but its working (and covers all the date to JSON areas in my code) and will have to do for now. Any other suggestions are welcome though, I am sure there is a better way than this.
import grails.converters.JSON;
class BootStrap {
def init = { servletContext ->
JSON.registerObjectMarshaller(Date) {
TimeZone tz = TimeZone.getDefault();
def dateFormat = 'yyyy/MM/dd HH:mm'
return it?.format(dateFormat,tz)
}
这篇关于JQGrid日期格式化程序未正确应用本地时间偏移量:Grails的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!