Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

On client side, i use dd/MM/yyyy date format. The field use a twitter bootstrap 3 datetime picker (https://eonasdan.github.io/bootstrap-datetimepicker/)

I enter via twitter bootstrap 3 datetime picker 24/07/2015
in my json i sent, i see: birthdate: "24/07/2015"

In my dto, i do

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd/MM/yyyy")
private Date birthdate;

When i receive the date on the server, in my dto see: 23/07/2015 19:00

One day is lost.

Any explication?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
297 views
Welcome To Ask or Share your Answers For Others

1 Answer

According to JacksonFAQDateHandling page:

All time objects that have associated TimeZone (java.util.Calendar etc) that Jackson constructs use the standard timezone (GMT), not the local time zone (whatever that might be). That is: Jackson defaults to using GMT for all processing unless specifically told otherwise.

In your case, it looks like the date is automatically being converted to GMT/UTC. Try to provide your local timezone explicitly to avoid UTC conversion [as mentioned in the question How come this time is off by 9 hours? (5 hours, 3 hours etc) on same page]:

@JsonFormat(shape=JsonFormat.Shape.STRING, pattern="dd/MM/yyyy", timezone="EST")

Secondly, I think you are using Date.toString() to print date. Note that java Date class is timezone independent but its toString() method uses the system's default timezone before printing.

Here it looks like 24/07/2015 00:00 UTC is being converted to 23/07/2015 19:00 EST by toString(). Both of these represent the same moment of time but in different timezones.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...