一般前端都是传给我们一个时间戳,
比如现有一个时间戳time,数据库有一个datetime类型的date列,此时我们应该怎么取对数据库进行筛选呢
先总结一下方法,时间戳只要转换成LocalDateTime类型就可以与数据库的datetime类型数据进行比较了
我们对他进行转换,如下:
Instant instant = Instant.ofEpochMilli(time);
ZoneId zoneId = ZoneId.systemDefault();
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zoneId);
然后我们再利用转换后的localdatetime,利用wrapper进行比较获取数据
QueryWrapper<Reservation> wrapper = new QueryWrapper<>();
TimeCountVo timeCountVo = new TimeCountVo();
wrapper.eq("date",localDateTime)
System.out.println(getOne(wrapper));
如果前端传来的是String字符串便不需要上面转换,如2024-12-07 15:00,这种String类型的数据是可以直接和数据库数据进行比较的