Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How does list get the month within a time interval

Shulou Source: shulou.com Published: 2022-06-01 12:44:24 10月04日 Update

This article mainly explains "how to get the month within a time interval by list". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to get the month within a time interval" together.

Dependence:

Joda-time joda-time 2.10.5import 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 yearMonth = getYearMonth (oneYear,twoYear,oneMonth,twoMonth); System.out.println (yearMonth);} private static List getYearMonth (int oneYear,int twoYear, int oneMonth,int twoMonth) {return getYearMonth (oneYear,twoYear,oneMonth,twoMonth, "-") } private static List getYearMonth (int oneYear,int twoYear, int oneMonth,int twoMonth,String separator) {List yearMonth = new ArrayList (); if (oneYear < twoYear) {if (oneYear + 1 = = twoYear) {/ / two years are relational 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 getYearMonth (int year,String separator, int fromMonth,int toMonth) {List yearMonth = new ArrayList (); for (int I = fromMonth; I

Tags: Time month study content two namely year train of thought situation article more knowledge knowledge point article result follow problem practice push research Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Huawei OPPO Reno MariaDB Shulou Information