1、如图所示,mysql中存在一个字段create_time,其数据类型为datetime;

实体类中将mysql数据库中datetime类型字段所对应实体类的属性进行格式化操作

2、对应的实体类

public class RealAuthDO implements Serializable {
    private static final long serialVersionUID = 1L;
    private Date createTime;    
    private String creatTimeStr;
    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
    public Date getCreateTime() {
        return createTime;
    }
 
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
        String time = sdf.format(createTime);
        setCreatTimeStr(time);
    }
 
    public String getCreatTimeStr() {
        return creatTimeStr;
    }
 
    public void setCreatTimeStr(String creatTimeStr) {
        this.creatTimeStr = creatTimeStr;
    }
}

3、如果想在页面上使用,转化格式后的create_time,不妨直接使用createTimeStr

实体类中将mysql数据库中datetime类型字段所对应实体类的属性进行格式化操作

4、其转化后的日期时间格式如下:

实体类中将mysql数据库中datetime类型字段所对应实体类的属性进行格式化操作

 

 

注意:   使用注解对日期进行格式化的 @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss", timezone="GMT+8")

 

 

转 : https://blog.csdn.net/liubin5620/article/details/80309518

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-03
  • 2021-11-27
  • 2021-09-03
  • 2022-12-23
  • 2021-06-21
猜你喜欢
  • 2022-01-19
  • 2022-12-23
  • 2021-11-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案