//时间格式化
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = ""yyyy-MM-dd HH:mm:ss")
//区别
@JsonFormat用于后端传给前端的时间格式转换,@DateTimeFormat用于前端传给后端的时间格式转换
在需要查询时间的数据库字段对应的实体类的属性上添加@JsonFormat
我们在对应的接收前台数据的对象的属性上加@DateTimeFormat
//常用时间格式
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd 23:59:59");
//获取当前时间
String toDay = df.format(new Date());
String toDay1 = df.format(new Date(System.currentTimeMillis()));
//时间戳,用于时间计算
System.currentTimeMillis();
//昨天时间
String yesterdayDate =df.format(new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 24));
Java时间格式问题
最新推荐文章于 2022-11-21 08:30:00 发布