亚洲免费在线视频-亚洲啊v-久久免费精品视频-国产精品va-看片地址-成人在线视频网

您的位置:首頁技術文章
文章詳情頁

在java中獲取List集合中最大的日期時間操作

瀏覽:2日期:2022-08-27 10:19:38

取List集合中最大的日期, 可以用Date max = Collections.max(dateList);, 傳入一個日期集合, 就可以獲取, 工作中有這個需求, 就查找到這個,

代碼如下

} else { /** 獲取此專題下的所有內容的最新時間 */Long featureId = this.communityFeatureMapper.selectFeatureIdByLabelId(labelId);List<CommunityFeatureRelation> communityFeatureRelationList = this.communityFeatureRelationMapper.selectByFeatureId(featureId);List<Date> dateList = Lists.newArrayList();for (CommunityFeatureRelation communityFeatureRelation : communityFeatureRelationList) {CommunityProduct communityProduct =this.communityProductMapper.selectContentIdByProductIdAndType(communityFeatureRelation.getProductId(),BaseConstans.ARTICLE_YIFABU);CommunityArticle communityArticle = this.communityArticleMapper.selectByPrimaryKey(communityProduct.getContentId());dateList.add(communityArticle.getReleaseTime()); }if (!CollectionUtils.isEmpty(dateList)) {Date max = Collections.max(dateList);/** 內容->添加專題-此專題下的合伙人getReleaseTime 更新, 若此專題下不存在合伙人, 則不更新 */Long productId = this.communityProductMapper.selectIdByContentIdAndType(featureId, BaseConstans.FOUR);CommunityPartner communityPartner = this.communityPartnerMapper.selectByPartnerId(productId);if (!StringUtils.isEmpty(communityPartner)) {communityPartner.setCreateTime(max);communityPartnerMapper.updateByPrimaryKeySelective(communityPartner); }} CommunityProduct communityProduct = this.communityProductMapper.selectContentIdByProductIdAndType(prodId, proType);

補充知識:java自定義List中的sort()排序方法,用于日期排序

1、問題描述

List是java中一個有序可重復的的集合,其中自帶的.sort()排序方法,該方法在針對純數字類型List集合排序的時候很有效。但是對于裝入其他類型的List集合,自帶的sort()方法排序我們很難控制,比如一個日期集合的排序。

2、解決方法:

java中List允許我們自定義sort()排序方法,以下自定義了List集合的sort排序方法,用于對一個字符串類型的日期集合進行排序。

//待排序的集合List<String> list=new ArrayList<String>();list.add('2019-06');list.add('2019-11');list.add('2019-02');list.add('2019-09');list.add('2019-05');//自定義list排序,集合數據(月份)按升序排序;final SimpleDateFormat sdft = new SimpleDateFormat('yyyy-MM');Collections.sort(list, new Comparator<String>(){ @Override public int compare(String month1, String month2) { int mark = 1; try { Date date1 = sdft.parse(month1); Date date2 = sdft.parse(month2); if(date1.getTime() < date2.getTime()){ mark = -1;//調整順序,-1為不需要調整順序; } if(month1.equals(month2)){ mark = 0; } } catch (ParseException e) { LOG.error('日期轉換異常', e); e.printStackTrace(); } return mark; } //compare});

3、其他

另外java兩個日期類型的對象也可以用如下方法進行比較。

Date() date1=new Date();Date() date2=new SimpleDateFormat('yyyy-MM-dd').parse('2019-06-11');Boolean flag;if(date1.before(date2)){ flag=true;}a.before(b);該方法是判斷a日期是否小于b日期,返回的是一個布爾類型結果。

以上這篇在java中獲取List集合中最大的日期時間操作就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持好吧啦網。

標簽: Java
相關文章:
主站蜘蛛池模板: 99热在线免费 | 亚洲男人天堂视频 | 欧美色黄毛片 | 亚洲综合成人网在线观看 | 伊人短视频 | 暖暖免费高清日本一区二区三区 | 成人高清 | 亚洲精品a | 俄罗斯18videosex性欧美成人 | 国产精品久久久久久久久久久威 | 天天夜夜久久 | 免费一级特黄欧美大片久久网 | 成人久久久观看免费毛片 | 午夜两性视频 | 国内精品一区二区2021在线 | 亚洲三级中文字幕 | 亚欧成人毛片一区二区三区四区 | 美国免费高清一级毛片 | 美女黄网站 | 美女被男人桶到嗷嗷叫爽网站 | 亚洲高清免费视频 | 欧美在线精品一区二区三区 | 亚洲福利视频精选在线视频 | 成人免费观看网欧美片 | 欧洲亚洲综合一区二区三区 | 黄色免费在线观看视频 | 日韩欧美一区二区中文字幕 | 免费看真人a一级毛片 | 99精品免费在线观看 | 美毛片 | 日韩中文字幕一在线 | 免费观看欧美精品成人毛片 | 美美女下面被cao爽 美女131爽爽爽做爰中文视频 | 久久精品视频6 | 精品欧美一区二区三区在线 | 亚洲国产成人久久一区www | 国产自偷自拍 | 日韩亚洲一区中文字幕在线 | 九九re6精品视频在线观看 | 中国人免费观看高清在线观看二区 | 国产精品手机在线亚洲 |