0

In one of my class, I have a Date object. Whenever I get the result from database via REST web service, the result always add 8hrs to my Date object.

Eg: Value in DB: 2017-01-01 00:00:00 GMT +08:00

Breakpoint before web service: 2017-01-01

After web service: 2017-01-01 08:00:00 GMT +08:00

Is there anything I need to do to configure this to get the following result?

=> 2017-01-01 00:00:00

I am using Spring, Jackson and hibernate

These are my jackson lib

  • jackson-annotations-2.8.4.jar
  • jackson-core-2.8.4.jar
  • jackson-databind-2.8.4.jar
  • jackson-datatype-hibernate5-2.8.4.jar
shadow
  • 800
  • 2
  • 16
  • 33
  • Can you share the code for better understanding of the problem? – Ole V.V. Apr 21 '17 at 10:32
  • 1
    Just a guess, this sounds like a time zone problem. As I read your strings, the 8 hours agree with your offset from UTC (GMT). – Ole V.V. Apr 21 '17 at 10:36
  • Do you need the date and the time, or just the date? – Ole V.V. Apr 21 '17 at 10:37
  • where is your db server and on which time zone is it running? same question for your web service implementation. – P.J.Meisch Apr 21 '17 at 19:12
  • @OleV.V. What i need is just date. Just updated my post. – shadow Apr 25 '17 at 07:21
  • I read that you should be able to use `java.time.LocalDate` with Jackson. See for example [this blog post: LocalDate java 8 Custom Serializer Jackson JSON Example](http://blog.chris-ritchie.com/2014/09/localdate-java-8-custom-serializer.html) and [this question: Java 8 LocalDate Jackson format](http://stackoverflow.com/questions/28802544/java-8-localdate-jackson-format). Not only should it eliminate your problem with the time, a `LocalDate` also models a date without time better/more precisely. You will want your database column to contain a date without time too of course, doesn’t it already? – Ole V.V. Apr 25 '17 at 08:22
  • @OleV.V. OK thanks. I will try it out. and yes of course, my DB column has already catered for date only. – shadow Apr 27 '17 at 02:29

0 Answers0