关于计算日历
private int xianshilianxu(int year,int month,int day,String user) { int jianchishijian=0; TextView textView1 = findViewById(R.id.hunong); String riqi1 = year + "-" + (month + 1) + "-" + day; if (chaxunriqi(year,month,day,user)>=0) { jianchishijian = dedaolianxvtianshu(year, month, day,user,true); String yijianchitext="已坚持"+jianchishijian+"天"; textView1.setText(yijianchitext); }else { jianchishijian = dedaolianxvtianshu(year, month, day,user,false); String yijianchitext="已坚持"+jianchishijian+"天"; textView1.setText(yijianchitext); } return jianchishijian; } private int dedaolianxvtianshu(int year,int month,int day,String usernname,boolean flag)//flag=true指今天已经打卡 { int jianchitian=0; android.icu.util.Calendar calendar= android.icu.util.Calendar.getInstance(); calendar.set(year,month,day); if(!flag) { calendar.add(android.icu.util.Calendar.DAY_OF_MONTH, -1); year = calendar.get(android.icu.util.Calendar.YEAR); month = calendar.get(android.icu.util.Calendar.MONTH);//实际月份需要加1 day = calendar.get(android.icu.util.Calendar.DATE); } while(true) { if (chaxunriqi(year,month,day,usernname)>=0) { jianchitian++; calendar.add(android.icu.util.Calendar.DAY_OF_MONTH, -1); year = calendar.get(android.icu.util.Calendar.YEAR); month = calendar.get(android.icu.util.Calendar.MONTH);//实际月份需要加1 day = calendar.get(android.icu.util.Calendar.DATE); } else { break; } } return jianchitian; }
标签:24,总结,int,month,23.3,year,calendar,android,icu From: https://www.cnblogs.com/laobing6214/p/17253385.html