gpt4 book ai didi

android - 一个月中的天数数组并从每个位置获取值

转载 作者:行者123 更新时间:2023-11-29 23:18:50 25 4
gpt4 key购买 nike

这是我的数据结构,它是二月份的所有日子。我如何根据数据使今天的日期相等,例如今天是 22 = 21。 enter image description here

这是我当前的代码

 SimpleDateFormat day = new SimpleDateFormat("dd");
Calendar calendar = Calendar.getInstance();

int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);


ArrayList<String> allDays = new ArrayList<>();
for(int i = 0; i < daysInMonth; i++){

allDays.add(day.format(calendar.getTime()));


}

最佳答案

试试这段代码,

SimpleDateFormat day = new SimpleDateFormat("dd");
Calendar calendar = Calendar.getInstance();

List<String> allDays = new ArrayList<>();
for(int i = 0; i < calendar.getActualMaximum(Calendar.DAY_OF_MONTH); i++){
allDays.add(i, String.valueOf(i+1));
}

this will be your allDays list.

关于android - 一个月中的天数数组并从每个位置获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54822127/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com