1. 程式人生 > >spring-mongodb 時間區間查詢

spring-mongodb 時間區間查詢

Query query = new Query();

SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");//時間格式要與mongodb對應

startDate = format.parse(filter.getValue().toString().replaceAll("-", "/"));

SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
endDate = format.parse(filter.getValue().toString().replaceAll("-", "/"));

query.addCriteria(Criteria.where("createtime").gte(startDate).lte(endDate));