在Jhipster项目响应JSON中为ZoneDateTime提供错误的日期格式

时间:2018-03-07 10:56:04

标签: spring-mvc spring-boot jhipster

public abstract class PrimaryBaseEntity {
@JsonFormat(pattern = "dd-MM-yyyy hh:mm:ss")
@Column(name = "rejected_date")
private ZonedDateTime rejectedDate;
}

//Extended above class
public class CountryChecker extends PrimaryBaseEntity

in application.yml below property added.

spring:
profiles:
    active: dev
    include: SeperateDatabase,no-liquibase
devtools:
    restart:
        enabled: false
    livereload:
        enabled: false # we use gulp + BrowserSync for livereload
jackson:
    #serialization.indent_output: true
    serialization.WRITE_DATES_AS_TIMESTAMPS: false

仍然以低于日期格式回复JSON  “rejectedDate”:1519828549,

这是JHIPSter生成的项目,请告诉我我们需要做些什么改变。

1 个答案:

答案 0 :(得分:0)

尝试在application.properties文件中提及此内容

spring.jackson.date-format= # Date format string (e.g. yyyy-MM-dd HH:mm:ss)

你可以使用getter方法将时间戳解析为“dd-MM-yyyy hh:mm:ss”

public abstract class PrimaryBaseEntity {

    @Column(name = "rejected_date")
    private ZonedDateTime rejectedDate;

    SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");

    public Date getRejectedDate() {
       return formatter.parse(rejectedDate);
    }
}