Mongodb將時(shí)間戳轉(zhuǎn)換為年月日日期
使用dateToString 方法進(jìn)行轉(zhuǎn)換 并且通過(guò)format指定轉(zhuǎn)換日期格式
? ? ? ? Integer userId=aaa;
? ? ? ? GroupOperation groupOperation = Aggregation.group(“day”).sum(“money”).as(“todayIncome”).count().as(“todayPayCount”);
? ? ? ? Aggregation aggregation = Aggregation.newAggregation(
? ? ? ? ? ? ? ? Aggregation.match(Criteria.where(“userId”).is(userId)),
? ? ? ? ? ? ? ? project(“userId”,”money”).andExpression(“{$dateToString: {date: { $add: {‘$createTime’, [0]} }, format: ‘%Y%m%d’}}”, new Date(28800000)).as(“day”),
? ? ? ? ? ? ? ? groupOperation,
? ? ? ? ? ? ? ? sort(Sort.Direction.ASC, “_id”)
? ? ? ? );
標(biāo)簽Mongodb,nbsp,如何,時(shí)間,轉(zhuǎn)換,年月日,日期
網(wǎng)友評(píng)論