Mongo-data 对日期类型数据的操作

一、Mongo直接操作日期类型:

db.guideline.find({'monitorDate': {'$gte' : new Date('2013-9-22 00:00:00'), '$lte' : new Date('2013-9-22 23:59:59')}})

或者

db.guideline.find({ "monitorDate" : { "$gte" : ISODate("2013-09-21T16:00:00Z"), "$lte" : ISODate("2013-09-22T15:59:59Z") } })


二、Spring-data的操作:

Query query = new Query();

//添加日期限制,只获取当天的信息
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
Date date = new Date();

try {
    query.addCriteria(Criteria.where("monitorDate").gte(format.parse(format.format(date))));
} catch (ParseException e) {
    e.printStackTrace();
}

你可能感兴趣的:(Mongo-data 对日期类型数据的操作)