软件下载吧文章资讯

分类分类

Mongodb 如何将时间戳转换为年月日日期

2024-03-09 11:51作者:下载吧

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”)
        );
展开全部

相关文章

说两句网友评论
    我要跟贴
    取消