简体   繁体   中英

Parse serialized date in Grails with proper time zone

I'm trying to bind date in Grails App. In application.yml I have databindings for default JavaScript date formats:

  grails:
    databinding:
      dateFormats:
        - "yyyy-MM-dd'T'hh:mm:ss.S'Z'"
        - "yyyy-MM-dd'T'HH:mm:ss'Z'"

In Groovy I'm creating object from params def entity = new Entity(params) and everything binds OK, but...

The problem is that I have wrong time zone in my Grails app, ie:

  1. In AngularJS I'm creating new Date - Thu Oct 22 2015 00:00:00 GMT+0200 (CEST) (this is string representation of Date object)
  2. Next I'm sending it via $http service, JSON payload looks like this: { date: "2015-10-21T22:00:00.000Z", another: "another:, property: "property" } . Date looks fine right now, Z at the end means it is UTC so Thu Oct 22 2015 00:00:00 GMT+0200 (CEST) - 2 hours => 2015-10-21T22:00:00.000Z

  3. In Grails I'm doing def entity = new Entity(params) and here is problem, entity.date is equals to Wed Oct 21 22:00:00 CEST 2015 which means that Groovy/Grails parsed string 2015-10-21T22:00:00.000Z as CEST time zone not UTC

So how can I force Grails to load date with proper format?

PS Both the web browser and computer is working with CEST time zone.

I'm using Grails 3.0

Proper datetime string is yyyy-MM-dd'T'HH:mm:ss.SSSX .

In next versions this should be fixed and JavaScript datetime strings will be parsed via default parser.

More:

https://github.com/grails/grails-core/issues/9367 https://github.com/grails/grails-core/issues/9368

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM