获取list中时间最大或者最小的方式

//根据产品的有效期获取合同的有效期
List fwqxList = new ArrayList<>();
for (Map stringObjectMap : htProductList) {
    String fwyxqq = stringObjectMap.get("FWYXQ_Q").toString().replace("-", "");
    String fwyxqz = stringObjectMap.get("FWYXQ_Z").toString().replace("-", "");
    fwqxList.add(fwyxqq);
    fwqxList.add(fwyxqz);
}

// 有效期起
String maxTime = fwqxList.stream().max(String::compareTo).get();
String maxTimeYear = maxTime.substring(0, 4);
String maxTimeMonth = maxTime.substring(4, 6);
String maxTimeDay = maxTime.substring(6, 8);

// 有效期止
String minTime = fwqxList.stream().min(String::compareTo).get();
String minTimeYear = minTime.substring(0, 4);
String minTimeMonth = minTime.substring(4, 6);
String minTimeDay = minTime.substring(6, 8);

htYxqQsZzMap.put("VIP_YXQ_Q", minTimeYear + "-" + minTimeMonth + "-" + minTimeDay);
htYxqQsZzMap.put("VIP_YXQ_Z", maxTimeYear + "-" + maxTimeMonth + "-" + maxTimeDay);

 

你可能感兴趣的:(项目二)