springBoot returns yyyy-MM-dd HH:mm:ss time type json

@GetMapping("/currentDateTime")
public Date currentDateTime() {
    
    
    return new Date();
}

The Date json time format returned by default is
Insert picture description here

If you want to return a custom format like "yyyy-MM-dd HH:mm:ss", you need to configure the following

spring:
  # 设置返回json的全局时间格式
  jackson:
    date-format: yyyy-MM-dd HH:mm:ss
    time-zone: GMT+8

Insert picture description here

Guess you like

Origin blog.csdn.net/QiuHaoqian/article/details/111416005