实体类中Date 时间格式
1、第一种
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
直接获取插入数据库 ,获取方法:
(select now()::timestamp)
String todayDate = DateUtil.format(new Date(),"yyyy-MM-dd");
2、第二种
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
获取时间方法:
Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String createTime = simpleDateFormat.format(date);
Timestamp timestamp = Timestamp.valueOf(createTime);
topicInfo.setCreateTime(timestamp);