获取当前时间,用到date函数,但是时间的格式需要提前统一,否则在进行时间运算时会报错。
public List<book> select2(int id) {
String sql = "select * from jieyue where idr='" + id + "'";
Connection connection = DBUtil_reader.getConnection();
PreparedStatement st = null;
List<book> list = new ArrayList<>();
ResultSet rs = null;
book stuid = null;
Dao_book dao = new Dao_book();
try {
st = connection.prepareStatement(sql);
st.executeQuery(sql);
rs = st.executeQuery(sql);
while (rs.next()) {
int id1 = rs.getInt("idb");
stuid = dao.Select(id1);
String time = dao.Select2(id1);
@SuppressWarnings("unused")
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDate time1 = LocalDate.parse(time, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
LocalDate today = LocalDate.now();
Period p = Period.between(time1, today);
int day = p.getYears() * 365 + p.getMonths() * 30 + p.getDays();
if (day > 90)
list.add(stuid);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
DBUtil_book.close(rs);
DBUtil_book.close(st);
DBUtil_book.close(connection);
}
return list;
}