List<Date>遍历格式化(List中的Date类型转换)

话不多说,直接上案例代码:

可复制代码:

// 将List集合中的字符串格式化
        SimpleDateFormat simple = new SimpleDateFormat("yy-MM-dd HH:mm");
        // new一个新的集合,来存放格式化的时间数据
        List<String> trend_date = new ArrayList<String>();
        // 将List中的Date集合全部格式化类型为"yy-MM-dd HH:mm"
        for (Date time : trend_time) {
            trend_date.add(simple.format(time).toString());
        }

 

注意事项:

使用format格式化完成后,集合中的Date类型转换成为String类型

猜你喜欢

转载自blog.csdn.net/qq_40820862/article/details/82355638