springBoot 返回 yyyy-MM-dd HH:mm:ss 时间类型的json

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

默认情况下返回的 Date json时间格式是
在这里插入图片描述

如果想要返回自定义的形如 “yyyy-MM-dd HH:mm:ss” 的格式需要进行以下配置

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

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/QiuHaoqian/article/details/111416005
今日推荐