There are several things at play here.
First, Spring's @DateTimeFormat
, when annotating a java.util.Date
field or parameter, uses a SimpleDateFormat
with its timezone set to UTC
.
Second, you've used DateTimeFormat.ISO.DATE
which represents
The most common ISO Date Format yyyy-MM-dd
, e.g. "2000-10-31".
In other words, it does not consider any timezone information in your date string (this doesn't really matter because your date string was rooted at Zulu anyway).
Third, you've provided a date string where everything but the iso
pattern gets ignored. The SimpleDateFormat
only cares about the 2017-01-24
part.
Since the timezone is set to UTC
, it considers the 2017-01-24
date as being rooted at UTC, at midnight, zero'ed hours, minutes, and seconds.
Finally, since your system's default time zone is Central Standard Time, ie. UTC-6), when you call toString
on the Date
object, it'll return a String
that is formatted with that time zone, ie. 6 hours before midnight.
Remember also that a Date
has no concept of a timezone. It is a timestamp.
To "fix" this, construct your @DateTimeFormat
with an appropriate pattern
that interprets both time and time zone. I would use
@DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSX") Date myDate
yyyy-MM-dd'T'HH:mm:ss.SSSZ
? – Peculiarity