Mongodb 如何將時間戳轉換為年月日日期
時間:2024-03-09 11:51作者:下載吧人氣:24
Mongodb將時間戳轉換為年月日日期
使用dateToString 方法進行轉換 并且通過format指定轉換日期格式
? ? ? ? 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”)
? ? ? ? );
標簽Mongodb,nbsp,如何,時間,轉換,年月日,日期
網友評論