Jackson @JsonFormat set date with one day less

前端 未结 4 1592
后悔当初
后悔当初 2020-12-13 04:59

I have been used Spring Date Rest with Spring Boot in my project. This project has a object and I have used the annotation @JsonFormat to format the date field that will be

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-13 05:46

    I'd go with setting ObjectMapper timezone as default JVM timezone:

        ObjectMapper objectMapper = new ObjectMapper();
        //Set default time zone as JVM timezone due to one day difference between original date and formatted date.
        objectMapper.setTimeZone(TimeZone.getDefault());
    

    It's a better solution if you don't know what timezone is used on a server environment.

提交回复
热议问题