JQGrid date formatter not applying local time offset correctly : Grails

泄露秘密 提交于 2019-12-25 05:01:40

问题


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?


回答1:


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)
        }


来源:https://stackoverflow.com/questions/15734768/jqgrid-date-formatter-not-applying-local-time-offset-correctly-grails

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