成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

list怎么獲取一個時間間隔內(nèi)月份

這篇文章主要講解了“l(fā)ist怎么獲取一個時間間隔內(nèi)月份”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“l(fā)ist怎么獲取一個時間間隔內(nèi)月份”吧!

創(chuàng)新互聯(lián)公司-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價比焉耆網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式焉耆網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋焉耆地區(qū)。費用合理售后完善,十余年實體公司更值得信賴。

依賴:

<dependency>
    <groupId>joda-time</groupId>
    <artifactId>joda-time</artifactId>
    <version>2.10.5</version>
</dependency>
import org.joda.time.DateTime;

import java.util.ArrayList;
import java.util.List;

public class Client {
    public static void main(String[] args) {
        Long startTime = 1599148799000L;
        Long endTime=1599148799000L;
        DateTime start = new DateTime(startTime);
        DateTime end = new DateTime(endTime);

        int oneYear = start.getYear();
        int oneMonth = start.getMonthOfYear();

        int twoYear = end.getYear();
        int twoMonth = end.getMonthOfYear();


        List<String> yearMonth = getYearMonth(oneYear,twoYear,oneMonth,twoMonth);

        System.out.println(yearMonth);


    }

    private static List<String> getYearMonth(int oneYear,int twoYear ,int oneMonth,int twoMonth){
       return getYearMonth(oneYear,twoYear,oneMonth,twoMonth,"-");
    }
    private static List<String> getYearMonth(int oneYear,int twoYear ,int oneMonth,int twoMonth,String separator){
        List<String> yearMonth = new ArrayList<>();
        if(oneYear < twoYear){
            if(oneYear + 1 == twoYear){// 兩個年份是間隔為1的關(guān)系
                yearMonth.addAll(getYearMonth(oneYear,separator,oneMonth,12));
                yearMonth.addAll(getYearMonth(twoYear,separator,1,twoMonth));
                return yearMonth;
            }else {
                while (oneYear < twoYear){
                    yearMonth.addAll(getYearMonth(oneYear,separator,1,12));
                    oneYear +=1;
                }
                yearMonth.addAll(getYearMonth(twoYear,separator,1,twoMonth));
            }
        }else {
            yearMonth.addAll(getYearMonth(twoYear,separator,oneMonth,twoMonth));
        }
        return yearMonth;
    }

    private static List<String> getYearMonth(int year,String separator ,int fromMonth,int toMonth){
        List<String> yearMonth = new ArrayList<>();
        for (int i = fromMonth; i <= toMonth; i++) {
            if(i< 10){
                yearMonth.add(year+separator+"0"+i);
            }else {
                yearMonth.add(year+separator+i);
            }
        }
        return yearMonth;
    }
}

結(jié)果

[2020-09]

感謝各位的閱讀,以上就是“l(fā)ist怎么獲取一個時間間隔內(nèi)月份”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對list怎么獲取一個時間間隔內(nèi)月份這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識點的文章,歡迎關(guān)注!

分享題目:list怎么獲取一個時間間隔內(nèi)月份
轉(zhuǎn)載來源:http://jinyejixie.com/article30/jpodpo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供標(biāo)簽優(yōu)化域名注冊、手機(jī)網(wǎng)站建設(shè)靜態(tài)網(wǎng)站、ChatGPT響應(yīng)式網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁設(shè)計
会同县| 舒兰市| 阜城县| 洪洞县| 乌什县| 吉林市| 包头市| 抚松县| 梅河口市| 阜宁县| 马鞍山市| 泗洪县| 洞头县| 车险| 东山县| 商都县| 曲麻莱县| 平远县| 明星| 平罗县| 昆山市| 永寿县| 望奎县| 彝良县| 沙湾县| 苏尼特左旗| 阳谷县| 布拖县| 芷江| 共和县| 淳安县| 南京市| 马山县| 桑植县| 巴塘县| 禄丰县| 眉山市| 龙州县| 罗田县| 固始县| 孙吴县|