I have a spring-boot application with a controller that handles some requests with a date passed as a query parameter. E.g URI for request:
http://localhost:8081/test/read?from=2018-01-01T00:00:00Z
However, using the @RequestParam annotation to parse the date from the URI, I am getting a date in the local timezone, not the UTC timezone (as indicated by the 'Z').
I've tried setting the jdbctemplate time zone, the java.util.timezone and the spring.jackson.time_zone in application.properties, but that didn't help.
@RequestMapping(value = "test/read", method = RequestMethod.GET)
public ResponseEntity<String> get(
@RequestParam(value="from") @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'") final Date from)
// value of date in 'from' is in local timezone
The value should be in the UTC timezone, due to the trailing 'Z' in the pattern passed to @DateTimeFormat.
Any ideas for what I'm missing here?
java.util.Date
doesn't have a time zone, it is a wrapper around a long with the number of milliseconds since 1-1-1970 00:00 UTC. Its defaulttoString()
will render the value in the default JVM time zone. You may want to consider switching to thejava.time
classes instead. – Mark Rotteveel