美文网首页
根据输入时间获取月份

根据输入时间获取月份

作者: 小小弓长张 | 来源:发表于2022-10-17 14:21 被阅读0次

public static void main(String[] args) {

try{

String beginDate="2022-02";

String endDate ="2023-01";

Date begin = DateUtils.parseDate(beginDate, "yyyy-MM");

Date end = DateUti1s.parseDate(endDate, "yyyy-MM");

Calendar c1 = Calendar.getInstance();

Calendar c2 = Calendar.getInstance();

c1.setTime(begin);

C2.setTime(end);

int startYear = c1.get(Calendar.YEAR);

int endYear = c2.get(Calendar.YEAR);

int starMonth = c1.get(Calendar.NONTH);

int endMonth = c2.get(Calendar.MONTH);

List<String> List =new ArrayList<>();

for (int i= startYear; i<= endYear; i++){

String date="";

if (startYear == endyear){

for (int i= starMonth; 1<= endMonth;i++){

if(1<9){

date ="0"+(j+1);

}else {

date=""+(j+1);

}

list.add(date);

}

}else{

if (i == startyear) {

for (int j= starMonth; j< 12;j++)

if (j<9){

date ="0"+ (j+ 1);

} else {

date ="" + (j+1);

}

list.add(date);

}

}else if (i == endYear) {

for (int j=0; j<= endMonth; j++){

if (j<9){

date = "0"+ (j+ 1);

} else {

date = "" + (j+ 1);

}

list.add(date);

}

} else{

for (int j=0;j<12;j++){

if (j<9){

date = "0"+ (j+ 1);

} else {

date=""+(j+1);

}

List.add(date);

}

}

}

}

fot(int i=0; i< list.size();i++){

System.out.println(List.get(i));

} catch (Exception e){

e.printStackTrace();

}

}

相关文章

网友评论

      本文标题:根据输入时间获取月份

      本文链接:https://www.haomeiwen.com/subject/ndcdzrtx.html