av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術(shù)文章
文章詳情頁

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

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

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

代碼如下

} else { /** 獲取此專題下的所有內(nèi)容的最新時(shí)間 */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);/** 內(nèi)容->添加專題-此專題下的合伙人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);

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

1、問題描述

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

2、解決方法:

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

//待排序的集合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排序,集合數(shù)據(jù)(月份)按升序排序;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;//調(diào)整順序,-1為不需要調(diào)整順序; } if(month1.equals(month2)){ mark = 0; } } catch (ParseException e) { LOG.error('日期轉(zhuǎn)換異常', e); e.printStackTrace(); } return mark; } //compare});

3、其他

另外java兩個(gè)日期類型的對(duì)象也可以用如下方法進(jìn)行比較。

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日期,返回的是一個(gè)布爾類型結(jié)果。

以上這篇在java中獲取List集合中最大的日期時(shí)間操作就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Java
相關(guān)文章:
主站蜘蛛池模板: 国产成人av网站 | 国产人成 | 全部免费毛片在线播放高潮 | 五月天婷婷视频 | 久久国内精品 | 九九热精品 | 天堂成人在线 | 成人免费激情视频 | 国产一级一片免费播放放a 国产黄色大片 | 欧美三级 欧美一级 | 亚洲视频不卡 | 18在线观看免费入口 | 欧美性猛交xxxx | 日韩国产精品一区二区 | 欧美老少妇 | 国产综合视频 | 啪啪免费网站 | 亚洲国产欧美日韩在线 | 日韩免费一区二区三区 | 欧美黄色网 | 一级毛片播放 | 国产精品6 | 密乳av| av免费网站 | 极品美女一区二区三区 | 午夜免费av| 色羞羞 | 亚洲日本精品 | 91少妇丨porny丨 | 日本欧美亚洲 | 欧美精品在线观看视频 | 亚洲天堂国产 | 久久成人免费视频 | 日韩美女视频 | 国产一区二区网站 | 欧美一区二区三区视频 | 麻豆av在线免费观看 | 色香蕉网| 日韩专区在线观看 | 特级西西444www大胆免费看 | 中文字幕www |