0

I have simple question i use this configuration in application.properties in Spring Boot

spring.jackson.date-format=yyyy-MM-dd
spring.jackson.time-zone=Europe/Zagreb

but it's not working

when i use this annotation on class is work correct

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

Any idea what is bad?

serob
  • 34
  • 1
  • 4
  • Did you put `application.properties` in the right location? Did you spell the file name correctly (you say `...propertis` in your post). – Jim Garrison Jan 08 '22 at 23:05
  • Sorry my mistake i put in application.properties – serob Jan 08 '22 at 23:09
  • But this configuration not work i don't have idea why – serob Jan 08 '22 at 23:10
  • “but it's not working” does not make an acceptable question on Stack Overflow. Rewrite to be very specific and descriptive. Voting to close as needing details. – Basil Bourque Jan 08 '22 at 23:12
  • Dates do not have a time zone. – Basil Bourque Jan 08 '22 at 23:13
  • In json i have timestamp in wrong timezone i try use this configuration spring.jackson.date-format=yyyy-MM-dd spring.jackson.time-zone=Europe/Zagreb but nothing change Use this i have correct date @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd",timezone = "Europe/Zagreb") I don't now why configuration global in application.properties not work this my problem – serob Jan 08 '22 at 23:15
  • Yes, and her format is timestamp – serob Jan 08 '22 at 23:17
  • “yyyy-MM-dd” makes a date-only, not a timestamp. In Java use `LocalDate`, and in standard SQL use `DATE`. A timestamp is more. A timestamp is composed of a date, a time-of-day, and a time zone or offset-from-UTC (usually an offset of zero in database work). In Java use `OffsetDateTime` for exchanging values with a database, and in standard SQL use `TIMESTAMP WITH TIME ZONE`. – Basil Bourque Jan 08 '22 at 23:48
  • Ok, thank but what do you think why global config not work? – serob Jan 08 '22 at 23:58
  • We don't know what you mean by "not work" so we can't answer. You need to provide explicit examples that demonstrate the issue. – Jim Garrison Jan 09 '22 at 00:35
  • According to the documentation Formatting JSON Dates in Spring Boot, it should set the global date format and timezone in json, but when I use it, it has no effect, the returned date has the form of a timestamp, when I use the @JsonFormat annotation for a given DTO field is ok, I'm curious why this global configuring with application.properties doesn't change anything return is timestamp, which I possibly do wrong. Sorry for incomprehensible questions. – serob Jan 09 '22 at 01:48
  • I don't find solution why configuration on application.properties not work, just i use this ammotation on dtos Date fields @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd",timezone = "Europe/Zagreb") – serob Jan 10 '22 at 02:12

0 Answers0