Home  >  Q&A  >  body text

android - 如何根据一个周期遍历一个日历

具体的情况是这样的,目标是做一个日历,想在某个周期(比如20天)的日子里显示固定的文字(比如上班)

我暂时制作出了一个周期的,不知道按这个周期来有什么好的办法,需要涉及到计算年月日的话比较麻烦。。

阿神阿神2766 days ago667

reply all(2)I'll reply

  • 黄舟

    黄舟2017-04-17 16:03:32

    Does the original poster want to ask how to calculate the year, month and day conveniently?

    Recommend a java date library: http://joda-time.sourceforge.net/apidocs/org/joda/time/DateTime.html

    Just keep calling functions like plusDays, minusDays. It's very convenient. You don't need to deal with various boundary conditions such as leap year or normal year, 30 days or 31 days.

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 16:03:32

    I did it myself. . It turns out it’s not that difficult
    Just write a tool class

    public static int DateDifferentSum(Date date1,Date date2){
            calendar1.setTime(date1);
            calendar2.setTime(date2);
            int dayCount = (int) ((calendar1.getTimeInMillis()-calendar2.getTimeInMillis())/(1000*3600*24));
            return dayCount;
        }

    reply
    0
  • Cancelreply