• Android 日期筛选器


    Android日期筛选

    最近接到了一个新的需求:
    通过一个日期选择器筛选出自己想要的特定日期
    先上效果图:

    日期筛选器效果

    实现思路及过程

    我这里是用RecyclerView实现的这个效果,将RecycleView分为两部分,头部只显示月份,日期则放在了第二部分,通过点击动态修改总数据的itemState 状态实现其效果 最重要的:(通过切换上个月下个月因此状态的改变不能只改变当前数据,需要一个总数据容器记录所有数据,当点击状态发生变化,修改总数据中的当前选中的状态)
    先来看我的实体类:

    public class DateBean {
        //item类型
        public static int item_type_day = 1;//日期item
        public static int item_type_month = 2;//月份item
        int itemType = 1;//默认是日期item
    
        //item状态
        public static int ITEM_STATE_BEGIN_DATE = 1;//开始日期
        public static int ITEM_STATE_END_DATE = 2;//结束日期
        public static int ITEM_STATE_SELECTED = 3;//选中状态
        public static int ITEM_STATE_NORMAL = 4;//正常状态
    
        public int itemState = ITEM_STATE_NORMAL;
    
        Date date;//具体日期
        String day;//一个月的某天
        String monthStr;//YY-MM
    
        int position;
        int level;
    
    
        public int getItemState() {
            return itemState;
        }
    
        public void setItemState(int itemState) {
            this.itemState = itemState;
        }
    
        public int getItemType() {
            return itemType;
        }
    
        public void setItemType(int itemType) {
            this.itemType = itemType;
        }
    
        public String getMonthStr() {
            return monthStr;
        }
    
        public void setMonthStr(String monthStr) {
            this.monthStr = monthStr;
        }
    
        public static int getItem_type_month() {
            return item_type_month;
        }
    
        public static void setItem_type_month(int item_type_month) {
            DateBean.item_type_month = item_type_month;
        }
    
        public static int getItem_type_day() {
            return item_type_day;
        }
    
        public static void setItem_type_day(int item_type_day) {
            DateBean.item_type_day = item_type_day;
        }
    
        public String getDay() {
            return day;
        }
    
        public void setDay(String day) {
            this.day = day;
        }
    
        public Date getDate() {
            return date;
        }
    
        public void setDate(Date date) {
            this.date = date;
        }
    
        public int getPosition() {
            return position;
        }
    
        public void setPosition(int position) {
            this.position = position;
        }
    
        public int getLevel() {
            return level;
        }
    
        public void setLevel(int level) {
            this.level = level;
        }
    
    
    
        @Override
        public String toString() {
            return "DateBean{" +
                    "itemType=" + itemType +
                    ", itemState=" + itemState +
                    ", date=" + date +
                    ", day='" + day + '\'' +
                    ", monthStr='" + monthStr + '\'' +
                    '}';
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108

    详细的都有注释 这里就不再啰嗦了

    Aadpter内的内容如下:

    public class CalendarAdapter extends BaseAdapter<DateBean, RecyclerView.ViewHolder>{
    
    
        private OnDateSelect dateSelect;
    
        public CalendarAdapter(Context context){
            super(context);
        }
    
        @Override
        protected RecyclerView.ViewHolder onCreateChildViewHolder(ViewGroup parent, int viewType) {
    
            if (viewType==DateBean.item_type_month){
              return new MonthViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_month, parent, false));
            }else {
                return new DayViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_day, parent, false));
            }
    
        }
    
        @Override
        protected void onBindDataViewHolder(RecyclerView.ViewHolder holder, int position, DateBean dateBean) {
             if (holder instanceof MonthViewHolder){
                 ((MonthViewHolder) holder).mTvMonth.setText(dateBean.monthStr);
             }else if(holder instanceof DayViewHolder){
                 ((DayViewHolder) holder).mTvDay.setText(dateBean.getDay());
    
    
                 if (dateBean.getItemState() == DateBean.ITEM_STATE_BEGIN_DATE || dateBean.getItemState() == DateBean.ITEM_STATE_END_DATE) {
                     //开始日期或结束日期
                     ((DayViewHolder) holder).mTvDay.setTextColor(Color.WHITE);
    
                     if(dateBean.getItemState() == DateBean.ITEM_STATE_BEGIN_DATE){
                         holder.itemView.setBackgroundResource(R.drawable.day_start);
                     }
                     if(dateBean.getItemState() == DateBean.ITEM_STATE_END_DATE){
                         holder.itemView.setBackgroundResource(R.drawable.day_end);
                     }
    
                 } else if (dateBean.getItemState() == DateBean.ITEM_STATE_SELECTED) {
                     //选中状态
                     holder.itemView.setBackgroundColor(Color.parseColor("#40ffa500"));
                     ((DayViewHolder) holder).mTvDay.setTextColor(Color.WHITE);
                 } else {
                     //正常状态
                     holder.itemView.setBackgroundColor(Color.WHITE);
                     ((DayViewHolder) holder).mTvDay.setTextColor(Color.BLACK);
                 }
    
                 holder.itemView.setOnClickListener(new View.OnClickListener() {
                     @Override
                     public void onClick(View view) {
                         if (dateSelect!=null){
                             dateSelect.onDateSelectStatusChanged(dateBean,position);
                         }
                     }
                 });
             }
        }
    
        static class MonthViewHolder extends RecyclerView.ViewHolder {
            View view;
            TextView mTvMonth;
    
    
            public MonthViewHolder(@NonNull View itemView) {
                super(itemView);
                this.view = itemView;
                mTvMonth = itemView.findViewById(R.id.tv_month);
    
            }
        }
    
        static class DayViewHolder extends RecyclerView.ViewHolder {
            View view;
            TextView mTvDay;
    
    
            public DayViewHolder(@NonNull View itemView) {
                super(itemView);
                this.view = itemView;
                mTvDay = itemView.findViewById(R.id.tv_day);
    
            }
        }
    
        @Override
        public int getItemViewType(int position) {
            if (getMds().get(position).itemType==DateBean.item_type_month){
                return DateBean.item_type_month;
            }else {
                return DateBean.item_type_day;
            }
        }
    
        public interface OnDateSelect{
            void onDateSelectStatusChanged(DateBean dateBean,int position);
        }
    
        public void setOnDateSelect(OnDateSelect select){
            dateSelect = select;
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104

    Adapter里面主要是对每个状态下显示什么样的效果进行了效果展示,点击事件后的主要逻辑通过接口回调到了具体使用的Activity中去了。

    最最主要的Activity的代码:

    public class CalendarActivity extends AppCompatActivity {
        private RecyclerView mRecyclerView;
        private CalendarAdapter mCalendarAdapter;
        private LruCache<String, List<DateBean>> mDateBeanLruCache = new LruCache<>(3);
    
        private DateBean startDate,endDate;
        private TextView nextMonth;
        private TextView currentMonth;
        private ImageView imageView;
    
        @Override
        protected void onCreate(@Nullable Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_calendar);
            initView();
        }
    
        private void initView() {
            mRecyclerView = findViewById(R.id.calendar_list);
            mCalendarAdapter = new CalendarAdapter(this);
    
            TextView previousMonth = findViewById(R.id.tvUp);
            nextMonth = findViewById(R.id.tvDown);
            currentMonth = findViewById(R.id.tvMonth);
    
            previousMonth.setOnClickListener(view -> {
                initData("2022-07");
            });
    
            nextMonth.setOnClickListener(view -> {
                initData("2022-09");
            });
    
            currentMonth.setOnClickListener(view -> {
                initData("2022-08");
            });
    
            GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 7);
            gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
                @Override
                public int getSpanSize(int i) {
                    if (DateBean.item_type_month == mCalendarAdapter.getMds().get(i).getItemType()) {
                        return 7;
                    } else {
                        return 1;
                    }
                }
            });
            mRecyclerView.setLayoutManager(gridLayoutManager);
            mRecyclerView.setAdapter(mCalendarAdapter);
    
            mCalendarAdapter.setOnDateSelect((dateBean, position) -> {
                if (dateBean.day.isEmpty()){
                    return;
                }
                List<DateBean> dateBeans = mDateBeanLruCache.get(dateBean.monthStr);
                if (dateBeans==null || dateBeans.isEmpty()){
                    return;
                }
                //是否有开始时间
                if (startDate==null){
                    if (endDate==null || Integer.parseInt(endDate.day)>Integer.parseInt(dateBean.day)){
                        startDate = dateBean;
                        startDate.position = position;
                        mDateBeanLruCache.get(dateBean.monthStr).get(position).itemState = DateBean.ITEM_STATE_BEGIN_DATE;
                        mCalendarAdapter.notifyItemChanged(position,mDateBeanLruCache.get(dateBean.monthStr).get(position));
                        showDate();
                    }else if (Integer.parseInt(endDate.day)<Integer.parseInt(dateBean.day)){//结束时间小于当前选中时间
                        if (endDate.level>dateBean.level){//08>07
                            startDate = dateBean;
                            startDate.position = position;
                            mDateBeanLruCache.get(dateBean.monthStr).get(position).itemState = DateBean.ITEM_STATE_BEGIN_DATE;
                            mCalendarAdapter.notifyItemChanged(position,mDateBeanLruCache.get(dateBean.monthStr).get(position));
                            showDate();
                            return;
                        }
    
                        mDateBeanLruCache.get(dateBean.monthStr).get(position).itemState = DateBean.ITEM_STATE_END_DATE;
                        mCalendarAdapter.notifyItemChanged(position,mDateBeanLruCache.get(dateBean.monthStr).get(position));
                        mDateBeanLruCache.get(endDate.monthStr).get(endDate.getPosition()).itemState = DateBean.ITEM_STATE_BEGIN_DATE;
                        mCalendarAdapter.notifyItemChanged(endDate.getPosition(),mDateBeanLruCache.get(endDate.monthStr).get(endDate.getPosition()));
                        startDate = endDate;
                        startDate.position = endDate.position;
                        endDate = dateBean;
                        endDate.position = position;
                        showDate();
                    }
                }else {
                    if (Integer.parseInt(startDate.day)>Integer.parseInt(dateBean.day)){//开始日期 大于 当前选中的日期
                        if (endDate!=null){
                            if (endDate.level>dateBean.level){
                                mDateBeanLruCache.get(startDate.monthStr).get(startDate.getPosition()).itemState = DateBean.ITEM_STATE_NORMAL;
                                mCalendarAdapter.notifyItemChanged(startDate.position,mDateBeanLruCache.get(startDate.monthStr).get(startDate.position));
                                startDate = dateBean;
                                startDate.position = position;
                                mDateBeanLruCache.get(dateBean.monthStr).get(position).itemState = DateBean.ITEM_STATE_BEGIN_DATE;
                                mCalendarAdapter.notifyItemChanged(position,mDateBeanLruCache.get(dateBean.monthStr).get(position));
                                showDate();
                                return;
                            }
                            mDateBeanLruCache.get(endDate.monthStr).get(endDate.getPosition()).itemState = DateBean.ITEM_STATE_NORMAL;
                            mCalendarAdapter.notifyItemChanged(endDate.position,mDateBeanLruCache.get(endDate.monthStr).get(endDate.position));
                            showDate();
                        }
    
                        if (startDate.level<dateBean.level){//08>07
                            endDate = dateBean;
                            endDate.position = position;
                            mDateBeanLruCache.get(dateBean.monthStr).get(position).itemState = DateBean.ITEM_STATE_END_DATE;
                            mCalendarAdapter.notifyItemChanged(position,mDateBeanLruCache.get(dateBean.monthStr).get(position));
                            showDate();
                            return;
                        }
                        endDate = startDate;
                        endDate.position = startDate.position;
                        mDateBeanLruCache.get(endDate.monthStr).get(endDate.getPosition()).itemState = DateBean.ITEM_STATE_END_DATE;
                        mCalendarAdapter.notifyItemChanged(endDate.getPosition(),mDateBeanLruCache.get(endDate.monthStr).get(endDate.getPosition()));
                        startDate = dateBean;
                        startDate.position = position;
                        mDateBeanLruCache.get(dateBean.monthStr).get(position).itemState = DateBean.ITEM_STATE_BEGIN_DATE;
                        mCalendarAdapter.notifyItemChanged(position,mDateBeanLruCache.get(dateBean.monthStr).get(position));
                        showDate();
    
                    }else if (Integer.parseInt(startDate.day)<Integer.parseInt(dateBean.day)){//开始日期小于 当前选中的日期
                        if (endDate!=null){
                            if (Integer.parseInt(endDate.day)==Integer.parseInt(dateBean.day) && dateBean.level==endDate.level){
                                endDate = null;
                                mDateBeanLruCache.get(dateBean.monthStr).get(position).itemState = DateBean.ITEM_STATE_NORMAL;
                                mCalendarAdapter.notifyItemChanged(position,mDateBeanLruCache.get(dateBean.monthStr).get(position));
                                showDate();
                                return;
                            }
                            if (dateBean.level<endDate.level){
                                mDateBeanLruCache.get(startDate.monthStr).get(startDate.getPosition()).itemState = DateBean.ITEM_STATE_NORMAL;
                                mCalendarAdapter.notifyItemChanged(startDate.getPosition(),mDateBeanLruCache.get(startDate.monthStr).get(startDate.getPosition()));
                                startDate = dateBean;
                                startDate.position = position;
                                mDateBeanLruCache.get(dateBean.monthStr).get(position).itemState = DateBean.ITEM_STATE_BEGIN_DATE;
                                mCalendarAdapter.notifyItemChanged(position,mDateBeanLruCache.get(dateBean.monthStr).get(position));
                                showDate();
                                return;
                            }else {
                                mDateBeanLruCache.get(endDate.monthStr).get(endDate.getPosition()).itemState = DateBean.ITEM_STATE_NORMAL;
                                mCalendarAdapter.notifyItemChanged(endDate.position,mDateBeanLruCache.get(endDate.monthStr).get(endDate.position));
                                showDate();
                            }
                        }
    
                        if (startDate.level>dateBean.level){//08>07
                            endDate = startDate;
                            endDate.position = startDate.position;
                            startDate = dateBean;
                            startDate.position = position;
                            mDateBeanLruCache.get(dateBean.monthStr).get(position).itemState = DateBean.ITEM_STATE_BEGIN_DATE;
                            mCalendarAdapter.notifyItemChanged(position,mDateBeanLruCache.get(dateBean.monthStr).get(position));
                            mDateBeanLruCache.get(endDate.monthStr).get(endDate.getPosition()).itemState = DateBean.ITEM_STATE_END_DATE;
                            mCalendarAdapter.notifyItemChanged(endDate.getPosition(),mDateBeanLruCache.get(endDate.monthStr).get(endDate.getPosition()));
                            showDate();
                            return;
                        }
    
                        endDate = dateBean;
                        endDate.position = position;
                        dateBean.itemState = DateBean.ITEM_STATE_END_DATE;
                        mDateBeanLruCache.get(dateBean.monthStr).get(position).itemState = DateBean.ITEM_STATE_END_DATE;
                        mCalendarAdapter.notifyItemChanged(position,mDateBeanLruCache.get(dateBean.monthStr).get(position));
                        showDate();
                    }else if (Integer.parseInt(startDate.day)==Integer.parseInt(dateBean.day) && dateBean.level==startDate.level){//开始日期 等于 选中日期
                        startDate = null;
                        mDateBeanLruCache.get(dateBean.monthStr).get(position).itemState = DateBean.ITEM_STATE_NORMAL;
                        mCalendarAdapter.notifyItemChanged(position,mDateBeanLruCache.get(dateBean.monthStr).get(position));
                        showDate();
                    }else if (Integer.parseInt(startDate.day)==Integer.parseInt(dateBean.day) && dateBean.level>startDate.level){//日期相同 开始日期大于选中日期 ()
                        mDateBeanLruCache.get(endDate.monthStr).get(endDate.getPosition()).itemState = DateBean.ITEM_STATE_NORMAL;
                        mCalendarAdapter.notifyItemChanged(endDate.position,mDateBeanLruCache.get(endDate.monthStr).get(endDate.getPosition()));
                        endDate = dateBean;
                        endDate.position = position;
                        mDateBeanLruCache.get(dateBean.monthStr).get(position).itemState = DateBean.ITEM_STATE_END_DATE;
                        mCalendarAdapter.notifyItemChanged(position,mDateBeanLruCache.get(dateBean.monthStr).get(position));
                        showDate();
                    }
    
                }
            });
    
            //DateUtils.getCurrDate(DateUtils.MONTG_DATE_FORMAT)
            initData(DateUtils.getCurrDate(DateUtils.MONTG_DATE_FORMAT));
    
        }
    
    
        //计算 开始时间和结束时间之间的选中
        private void showDate(){
            if (startDate==null ||endDate==null) return;
    
    
            //算出
            List<DateBean> startDateBeanContainer = mDateBeanLruCache.get(startDate.monthStr);
            DateBean startDateBean = mDateBeanLruCache.get(startDate.monthStr).get(startDate.getPosition());
            int startLevel = startDateBean.getLevel();
    
            List<DateBean> endDateBeanContainer = mDateBeanLruCache.get(endDate.monthStr);
            DateBean endDateBean = mDateBeanLruCache.get(endDate.monthStr).get(endDate.getPosition());
            int endLevel = endDateBean.getLevel();
    
            if (startLevel==endLevel){//同一月份
                //清楚之前的状态
                resetAllStateSelected();
    
    
                for (int i = startDate.getPosition()+1; i < endDate.getPosition(); i++) {
                    mDateBeanLruCache.get(startDate.monthStr).get(i).itemState=DateBean.ITEM_STATE_SELECTED;
                    mCalendarAdapter.notifyItemChanged(i,mDateBeanLruCache.get(startDate.monthStr).get(i));
                }
    
    
            }else {
                //清楚之前的状态
                resetAllStateSelected();
    
                for (int i= startDate.getPosition()+1;i<startDateBeanContainer.size();i++){
                    mDateBeanLruCache.get(startDate.monthStr).get(i).itemState=DateBean.ITEM_STATE_SELECTED;
                    //mCalendarAdapter.notifyItemChanged(i,mDateBeanLruCache.get(startDate.monthStr).get(i));
                }
    
                for (int i=0;i<endDate.getPosition();i++){
                    mDateBeanLruCache.get(endDate.monthStr).get(i).itemState=DateBean.ITEM_STATE_SELECTED;
                }
                //间隔超过一个月
                if (startLevel+1<endLevel){
                    String[] split = startDate.monthStr.split("-");
                    int year = Integer.parseInt(split[0]);
                    int  week = Integer.parseInt(split[1]);
                    int nextWeek = 0;
                    int currentYear = 0;
                    if (week>=12){
                        nextWeek = 1;
                        currentYear = year+1;
                    }else {
                        currentYear = year;
                        nextWeek = week+1;
                    }
                    String key = currentYear + "-" + (nextWeek < 10 ? "0" + nextWeek : nextWeek);
                    for (int i = 0; i < mDateBeanLruCache.get(key).size(); i++) {
                        mDateBeanLruCache.get(key).get(i).itemState=DateBean.ITEM_STATE_SELECTED;
                    }
    
    
                }
    
                //间隔一个月 及多个月份
    //            for (int i = startLevel; i <= endLevel; i++) {
    //                for (int i=Integer.parseInt(startDateBean.getDay())+2;i
    //
    //                }
    //            }
    
            }
        }
    
    
    
        @SuppressLint("NotifyDataSetChanged")
        private void resetAllStateSelected() {
            Iterator<Map.Entry<String, List<DateBean>>> iterator = mDateBeanLruCache.snapshot().entrySet().iterator();
            while (iterator.hasNext()) {
                List<DateBean> value = iterator.next().getValue();
                for (int i = 0; i < value.size(); i++) {
                    if (value.get(i).itemState==DateBean.ITEM_STATE_SELECTED){
    
                        value.get(i).itemState = DateBean.ITEM_STATE_NORMAL;
                    }
                }
                mCalendarAdapter.notifyDataSetChanged();
            }
        }
    
    
    
    
        private void initData(String monthStr) {
            if (mDateBeanLruCache.get(monthStr)!=null && !mDateBeanLruCache.get(monthStr).isEmpty()){
                mCalendarAdapter.initMDatas(mDateBeanLruCache.get(monthStr));
                return;
            }
            int level = Integer.parseInt(DateUtils.getLastDayOfMonth(DateUtils.stringtoDate(monthStr,DateUtils.MONTG_DATE_FORMAT),"MM"));
    
            List < DateBean > dateBeans = new ArrayList<>();
            //先设置月份的
            DateBean monthBean = new DateBean();
            monthBean.setItemType(DateBean.item_type_month);
            monthBean.setMonthStr(monthStr);
            monthBean.setLevel(level);
            dateBeans.add(monthBean);
    
            //设置当前月的天数 获取当前月的第一天和最后一天
            int firstDayOfMonth = Integer.parseInt(DateUtils.getFirstDayOfMonth(DateUtils.stringtoDate(monthStr,DateUtils.MONTG_DATE_FORMAT),DateUtils.FORMAT_DATE));
            int lastDayOfMonth = Integer.parseInt(DateUtils.getLastDayOfMonth(DateUtils.stringtoDate(monthStr,DateUtils.MONTG_DATE_FORMAT),DateUtils.FORMAT_DATE));
    
    
    
            String week = DateUtils.getWeek(DateUtils.stringtoDate(monthStr+"-01",DateUtils.LONG_DATE_FORMAT));
            switch (week){
                case "星期一":
                    addDatePlaceholder(dateBeans,1,monthStr,level);
                    break;
                case "星期二":
                    addDatePlaceholder(dateBeans,2,monthStr,level);
                    break;
                case "星期三":
                    addDatePlaceholder(dateBeans,3,monthStr,level);
                    break;
                case "星期四":
                    addDatePlaceholder(dateBeans,4,monthStr,level);
                    break;
                case "星期五":
                    addDatePlaceholder(dateBeans,5,monthStr,level);
                    break;
                case "星期六":
                    addDatePlaceholder(dateBeans,6,monthStr,level);
                    break;
            }
    
    
            for (int i=firstDayOfMonth;i<=lastDayOfMonth;i++){
                DateBean dayBean = new DateBean();
                dayBean.setItemType(DateBean.item_type_day);
                dayBean.setMonthStr(monthStr);
                dayBean.setDay(String.valueOf(i));
                dayBean.setLevel(level);
    
                dayBean.setItemState(DateBean.ITEM_STATE_NORMAL);
                dateBeans.add(dayBean);
            }
            mDateBeanLruCache.put(monthStr,dateBeans);
            mCalendarAdapter.initMDatas(dateBeans);
        }
    
        private void addDatePlaceholder(List<DateBean> dateBeans, int count, String monthStr,int level) {
            for (int i = 0; i < count; i++) {
                DateBean dateBean = new DateBean();
                dateBean.setItemType(DateBean.item_type_day);
                dateBean.setMonthStr(monthStr);
                dateBean.setLevel(level);
                dateBeans.add(dateBean);
            }
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296
    • 297
    • 298
    • 299
    • 300
    • 301
    • 302
    • 303
    • 304
    • 305
    • 306
    • 307
    • 308
    • 309
    • 310
    • 311
    • 312
    • 313
    • 314
    • 315
    • 316
    • 317
    • 318
    • 319
    • 320
    • 321
    • 322
    • 323
    • 324
    • 325
    • 326
    • 327
    • 328
    • 329
    • 330
    • 331
    • 332
    • 333
    • 334
    • 335
    • 336
    • 337
    • 338
    • 339
    • 340
    • 341
    • 342
    • 343
    • 344
    • 345
    • 346
    • 347
    • 348
    • 349

    这里通过LRUcache 默认只记录最近使用的3个月份的数据,如果有其他的需求可以直接使用HashMap记录总数据(这里只是一个实现方式)

    这只是本人的初步完成的一个稿图,如果有其他的需求,可以在上面的实体类中进行修改,从而完成自己的需求。

    扩展类

    DateUtils.class

    public class DateUtils {
    
        // 格式:年-月-日 小时:分钟:秒
        public static final String FORMAT_ONE = "yyyy-MM-dd HH:mm:ss";
    
        // 格式:年-月-日 小时:分钟
        public static final String FORMAT_TWO = "yyyy-MM-dd HH:mm";
        // 格式:M月d
        public static final String SHORT_DATE_MONTH_FORMAT = "MM/dd";
        // 格式:年月日 小时分钟秒
        public static final String FORMAT_THREE = "yyyyMMdd-HHmmss";
    
        // 格式:年-月-日
        public static final String LONG_DATE_FORMAT = "yyyy-MM-dd";
        // 格式:yyyyMMdd
        public static final String LONG_DATE_FORMAT_TWO = "yyyyMMdd";
        //格式不 补零
        public static final String LONG_NO_ZOO_FORMAT = "yyyy-M-d";
        //格式 年
        public static final String YEAR_FORMAT = "yyyy年";
        // 格式:月-日
        public static final String SHORT_DATE_FORMAT = "MM-dd";
    
        public static final String FORMAT_DATE = "dd";
    
        //格式:04月-21日
        public static final String SHORT_DATE_FORMAT_TYPE = "MM月dd日";
    
        // 格式:小时:分钟:秒
        public static final String LONG_TIME_FORMAT = "HH:mm:ss";
    
        // 格式 :小时:分钟
        public static final String HOUR_MINUTE = "HH:mm";
    
        // 格式:年-月
        public static final String MONTG_DATE_FORMAT = "yyyy-MM";
        // 年的加减
        public static final int SUB_YEAR = Calendar.YEAR;
    
        // 月加减
        public static final int SUB_MONTH = Calendar.MONTH;
    
        // 天的加减
        public static final int SUB_DAY = Calendar.DATE;
    
        // 小时的加减
        public static final int SUB_HOUR = Calendar.HOUR;
    
        // 分钟的加减
        public static final int SUB_MINUTE = Calendar.MINUTE;
    
        // 秒的加减
        public static final int SUB_SECOND = Calendar.SECOND;
    
        // 格式:月-日-时-分
        public static final String SHORT_DATE_FORMAT_LONG_TIME = "MM-dd HH:mm";
    
        public static final String LONG_SECONDS_FORMAT = "mm:ss";
    
        private static String datePattern = "MM/dd/yyyy";
    
        private static String timePattern = datePattern + " HH:MM a";
        // 格式:年-月-日
        public static final String MONTG_DATE_FORMAT_YEAR_DAY = "yyyy年MM月dd日";
        // 格式:年-月
        public static final String MONTG_DATE_FORMAT_YEAR = "yyyy年MM月";
        // 格式:年-月-日 时-分
        public static final String DATE_FORMAT_YEAR_MONTH_DAY_HOUR_MIN = "yyyy年MM月dd日 HH:mm";
        // 格式:年-月-日 时-分-秒
        public static final String DATE_FORMAT_YEAR_MONTH_DAY_HOUR_MIN_SECOND = "yyyy年MM月dd日 HH:mm:ss";
    
        /**
         * Return default datePattern (MM/dd/yyyy)
         *
         * @return a string representing the date pattern on the UI
         */
        public static String getDatePattern() {
            return datePattern;
        }
    
        static final String dayNames[] = {"星期日", "星期一", "星期二", "星期三", "星期四",
                "星期五", "星期六"};
    
        @SuppressWarnings("unused")
        private static final SimpleDateFormat timeFormat = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss");
    
        public DateUtils() {
        }
    
        /**
         * 周代码转换
         *
         * @param week
         * @return
         */
        public static String DateToWeek(String week) {
            String day = null;
            if ("1".equals(week)) {
                day = "日";
            } else if ("2".equals(week)) {
                day = "一";
            } else if ("3".equals(week)) {
                day = "二";
            } else if ("4".equals(week)) {
                day = "三";
            } else if ("5".equals(week)) {
                day = "四";
            } else if ("6".equals(week)) {
                day = "五";
            } else if ("7".equals(week)) {
                day = "六";
            }
    
            return day;
        }
    
        /**
         * 把符合日期格式的字符串转换为日期类型
         *
         * @param dateStr
         * @return
         */
        public static Date stringtoDate(String dateStr, String format) {
            Date d = null;
            SimpleDateFormat formater = new SimpleDateFormat(format);
            try {
                formater.setLenient(false);
                d = formater.parse(dateStr);
            } catch (Exception e) {
                // log.error(e);
                d = null;
            }
            return d;
        }
    
        /**
         * 把符合日期格式的字符串转换为日期类型
         */
        public static Date stringtoDate(String dateStr, String format,
                                        ParsePosition pos) {
            Date d = null;
            SimpleDateFormat formater = new SimpleDateFormat(format);
            try {
                formater.setLenient(false);
                d = formater.parse(dateStr, pos);
            } catch (Exception e) {
                d = null;
            }
            return d;
        }
    
        /**
         * 把日期转换为字符串
         *
         * @param date
         * @return
         */
        public static String dateToString(Date date, String format) {
            String result = "";
            SimpleDateFormat formater = new SimpleDateFormat(format);
            try {
                result = formater.format(date);
            } catch (Exception e) {
                // log.error(e);
            }
            return result;
        }
    
        /**
         * 获取当前时间的指定格式
         *
         * @param format
         * @return
         */
        public static String getCurrDate(String format) {
            return dateToString(new Date(), format);
        }
    
        /**
         * 获取当前时间 yyyy-mm-dd hh:mm:ss
         */
        @SuppressLint("SimpleDateFormat")
        public static String getCurrentTime() {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date curDate = new Date(System.currentTimeMillis());// 获取当前时间
            return formatter.format(curDate);
        }
    
        /**
         * @param dateStr
         * @param amount
         * @return
         */
        public static String dateSub(int dateKind, String dateStr, int amount) {
            Date date = stringtoDate(dateStr, FORMAT_ONE);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            calendar.add(dateKind, amount);
            return dateToString(calendar.getTime(), FORMAT_ONE);
        }
    
        /**
         * 两个日期相减
         *
         * @param firstTime
         * @param secTime
         * @return 相减得到的秒数
         */
        public static long timeSub(String firstTime, String secTime) {
            long first = stringtoDate(firstTime, FORMAT_ONE).getTime();
            long second = stringtoDate(secTime, FORMAT_ONE).getTime();
            return (second - first) / 1000;
        }
    
        /**
         * 转换日期格式
         *
         * @param serverTime
         * @return
         */
        public static String getConversionTime(String serverTime, String format) {
            return dateToString(stringtoDate(serverTime, FORMAT_ONE), format);
        }
    
        /**
         * 时间精确计算
         *
         * @param serverTime
         */
        public static String getAccurateTime(String serverTime) {
            String alert = "";
            long dif = stringtoDate(getCurrDate(FORMAT_ONE), FORMAT_ONE).getTime() - stringtoDate(serverTime, FORMAT_ONE).getTime();
            if (dif < 60 * 1000) {
                alert = "刚刚";
                return alert;
            } else if (dif < 60 * 60 * 1000) {
                alert = (int) dif / 60 / 1000 + "分钟前";
                return alert;
            } else if (dif < 60 * 1000 * 60 * 24) {
                alert = (int) dif / 60 / 60 / 1000 + "小时前";
                return alert;
            } else if (dif > 60 * 60 * 1000 * 24 && dif < 60 * 60 * 1000 * 48) {
                alert = "昨天" + getConversionTime(serverTime, HOUR_MINUTE);
                return alert;
            } else {
                return dateToString(stringtoDate(serverTime, DateUtils.FORMAT_ONE), DateUtils.FORMAT_TWO);
            }
        }
    
    
        /**
         * 获得某月的天数
         *
         * @param year  int
         * @param month int
         * @return int
         */
        public static int getDaysOfMonth(String year, String month) {
            int days = 0;
            if (month.equals("1") || month.equals("3") || month.equals("5")
                    || month.equals("7") || month.equals("8") || month.equals("10")
                    || month.equals("12")) {
                days = 31;
            } else if (month.equals("4") || month.equals("6") || month.equals("9")
                    || month.equals("11")) {
                days = 30;
            } else {
                if ((Integer.parseInt(year) % 4 == 0 && Integer.parseInt(year) % 100 != 0)
                        || Integer.parseInt(year) % 400 == 0) {
                    days = 29;
                } else {
                    days = 28;
                }
            }
    
            return days;
        }
    
        /**
         * 获取某年某月的天数
         *
         * @param year  int
         * @param month int 月份[1-12]
         * @return int
         */
        public static int getDaysOfMonth(int year, int month) {
            Calendar calendar = Calendar.getInstance();
            calendar.set(year, month - 1, 1);
            return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
        }
    
        /**
         * 获得当前日期
         *
         * @return int
         */
        public static int getToday() {
            Calendar calendar = Calendar.getInstance();
            return calendar.get(Calendar.DATE);
        }
    
        /**
         * 获得当前月份
         *
         * @return int
         */
        public static int getToMonth() {
            Calendar calendar = Calendar.getInstance();
            return calendar.get(Calendar.MONTH) + 1;
        }
    
        /**
         * 获得当前年份
         *
         * @return int
         */
        public static int getToYear() {
            Calendar calendar = Calendar.getInstance();
            return calendar.get(Calendar.YEAR);
        }
    
        /**
         * 返回日期的天
         *
         * @param date Date
         * @return int
         */
        public static int getDay(Date date) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            return calendar.get(Calendar.DATE);
        }
    
        /**
         * 返回日期的年
         *
         * @param date Date
         * @return int
         */
        public static int getYear(Date date) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            return calendar.get(Calendar.YEAR);
        }
    
        /**
         * 返回日期的周
         *
         * @param date
         * @return
         */
        public static String getWeek(Date date) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            return dayNames[calendar.get(Calendar.DAY_OF_WEEK) - 1];
        }
    
        /**
         * 返回日期当前属于周几
         *
         * @param date
         * @return
         */
        public static int getCurrentWeekIndex(Date date) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            return calendar.get(Calendar.DAY_OF_WEEK) - 1;
        }
    
        /**
         * 返回日期所在周的周一
         *
         * @param date
         * @return
         */
        public static String getDateWeekMonday(Date date) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            int week = 0;
            if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
                week = 6;
            } else {
                week = calendar.get(Calendar.DAY_OF_WEEK) - 2;
            }
            calendar.add(Calendar.DAY_OF_YEAR, -week);
            return dateToString(calendar.getTime(), LONG_DATE_FORMAT);
        }
    
        /**
         * 返回日期所在周的周一
         *
         * @param date
         * @return
         */
        public static String getWeekMonday(Date date) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            int week = 0;
            if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
                week = 6;
            } else {
                week = calendar.get(Calendar.DAY_OF_WEEK) - 2;
            }
            calendar.add(Calendar.DAY_OF_YEAR, -week);
            return dateToString(calendar.getTime(), LONG_DATE_FORMAT);
        }
    
        /**
         * 得到本周周一
         *
         * @param date
         */
        public static String getMondayOfThisWeek(Date date) {
            Calendar c = Calendar.getInstance();
            c.setTime(date);
            int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1;
            if (day_of_week == 0)
                day_of_week = 7;
            c.add(Calendar.DATE, -day_of_week + 1);
            return dateToString(c.getTime(), LONG_DATE_FORMAT);
        }
    
        /**
         * 得到本周周日
         *
         * @param date
         */
        public static String getSundayOfThisWeek(Date date) {
            Calendar c = Calendar.getInstance();
            c.setTime(date);
            int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1;
            if (day_of_week == 0)
                day_of_week = 7;
            c.add(Calendar.DATE, -day_of_week + 7);
            return dateToString(c.getTime(), LONG_DATE_FORMAT);
        }
    
        /**
         * 返回日期所在下周的周一
         *
         * @param date
         * @return
         */
        public static String getNextWeekMonday(Date date) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            calendar.add(Calendar.WEEK_OF_MONTH, 1);
            int week = 0;
            if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
                week = calendar.get(Calendar.DAY_OF_WEEK) - 1;
            } else {
                week = calendar.get(Calendar.DAY_OF_WEEK) - 2;
            }
    
            calendar.add(Calendar.DAY_OF_YEAR, -week);
            return dateToString(calendar.getTime(), LONG_DATE_FORMAT);
        }
    
        /**
         * 返回日期所在上周的周一
         *
         * @param date
         * @return
         */
        public static String getLastWeekMonday(Date date) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            calendar.add(Calendar.WEEK_OF_MONTH, -1);
            int week = calendar.get(Calendar.DAY_OF_WEEK) - 2;
            calendar.add(Calendar.DAY_OF_YEAR, -week);
            return dateToString(calendar.getTime(), LONG_DATE_FORMAT);
        }
    
        /**
         * 返回日期所在周的周日
         *
         * @param date
         * @return
         */
        public static String getWeekSunday(Date date) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            int week = 7 - (calendar.get(Calendar.DAY_OF_WEEK) - 1);
            calendar.add(Calendar.DAY_OF_YEAR, week);
            return dateToString(calendar.getTime(), LONG_DATE_FORMAT);
        }
    
        /**
         * 返回日期所在下周的周日
         *
         * @param date
         * @return
         */
        public static String getNextWeekSunday(Date date) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            calendar.add(Calendar.WEEK_OF_MONTH, 1);
            int week = 7 - (calendar.get(Calendar.DAY_OF_WEEK) - 1);
            calendar.add(Calendar.DAY_OF_YEAR, week);
            return dateToString(calendar.getTime(), LONG_DATE_FORMAT);
        }
    
        /**
         * 返回日期所在下一周周一的日期
         *
         * @param date
         * @return
         */
        public static String getLastWeekSunday(Date date) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            calendar.add(Calendar.WEEK_OF_MONTH, -1);
            int week = 7 - (calendar.get(Calendar.DAY_OF_WEEK) - 1);
            calendar.add(Calendar.DAY_OF_YEAR, week);
            return dateToString(calendar.getTime(), LONG_DATE_FORMAT);
        }
    
        /**
         * 根据开始日期和结束日期,获取两个日期之间周数
         *
         * @param iBegin
         * @param iEnd
         * @return
         */
        public static int getWeek(Date iBegin, Date iEnd) {
    
            // 获取第一周周一的日期
            Date beginWeek = stringtoDate(getWeekMonday(iBegin), LONG_DATE_FORMAT);
            // 获取最后一周下周周一的日期
            Date endWeek = stringtoDate(getNextWeekMonday(iEnd), LONG_DATE_FORMAT);
            long day = dayDiff(beginWeek, endWeek);
            int weeks = 0;
            if (day > 0) {
                weeks = (int) (day / 7);
            }
    
            return weeks;
        }
    
        /**
         * 根据开始日期,获取当前时间的周次
         *
         * @param iBegin
         * @return
         */
        public static int getCurrentWeek(Date iBegin) {
    
            // 获取第一周周一的日期
            Date beginWeek = stringtoDate(getWeekMonday(iBegin), LONG_DATE_FORMAT);
            // 获取当前周 下周周一的日期
            Date endWeek = stringtoDate(
                    getNextWeekMonday(stringtoDate(getCurrDate(LONG_DATE_FORMAT),
                            LONG_DATE_FORMAT)), LONG_DATE_FORMAT);
            long day = dayDiff(beginWeek, endWeek);
            int weeks = 0;
            if (day > 0) {
                weeks = (int) (day / 7);
            }
    
            return weeks;
        }
    
        /**
         * 返回日期的月份,1-12
         *
         * @param date Date
         * @return int
         */
        public static int getMonth(Date date) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            return calendar.get(Calendar.MONTH) + 1;
        }
    
        /**
         * 计算两个日期相差的天数,如果date2 > date1 返回正数,否则返回负数
         *
         * @param date1 Date
         * @param date2 Date
         * @return long
         */
        public static long dayDiff(Date date1, Date date2) {
            return (date2.getTime() - date1.getTime()) / 86400000;
        }
    
        /**
         * 比较两个日期的年差
         *
         * @param before
         * @param after
         * @return
         */
        public static int yearDiff(String before, String after) {
            Date beforeDay = stringtoDate(before, LONG_DATE_FORMAT);
            Date afterDay = stringtoDate(after, LONG_DATE_FORMAT);
            return getYear(afterDay) - getYear(beforeDay);
        }
    
        /**
         * 比较指定日期与当前日期的差
         *
         * @param after
         * @return
         */
        public static int yearDiffCurr(String after) {
            Date beforeDay = new Date();
            Date afterDay = stringtoDate(after, LONG_DATE_FORMAT);
            return getYear(beforeDay) - getYear(afterDay);
        }
    
        /**
         * 比较指定日期与当前日期的差
         *
         * @param before
         * @return
         * @author chenyz
         */
        public static long dayDiffCurr(String before) {
            Date currDate = DateUtils.stringtoDate(currDay(), LONG_DATE_FORMAT);
            Date beforeDate = stringtoDate(before, LONG_DATE_FORMAT);
            return (currDate.getTime() - beforeDate.getTime()) / 86400000;
    
        }
    
        /**
         * 获取每月的第一周
         *
         * @param year
         * @param month
         * @return
         * @author chenyz
         */
        public static int getFirstWeekdayOfMonth(int year, int month) {
            Calendar c = Calendar.getInstance();
            c.setFirstDayOfWeek(Calendar.SATURDAY); // 星期天为第一天
            c.set(year, month - 1, 1);
            return c.get(Calendar.DAY_OF_WEEK);
        }
    
        /**
         * 获取每月的最后一周
         *
         * @param year
         * @param month
         * @return
         * @author chenyz
         */
        public static int getLastWeekdayOfMonth(int year, int month) {
            Calendar c = Calendar.getInstance();
            c.setFirstDayOfWeek(Calendar.SATURDAY); // 星期天为第一天
            c.set(year, month - 1, getDaysOfMonth(year, month));
            return c.get(Calendar.DAY_OF_WEEK);
        }
    
        /**
         * 获得当前日期字符串,格式"yyyy_MM_dd_HH_mm_ss"
         *
         * @return
         */
        public static String getCurrent() {
            Calendar cal = Calendar.getInstance();
            cal.setTime(new Date());
            int year = cal.get(Calendar.YEAR);
            int month = cal.get(Calendar.MONTH) + 1;
            int day = cal.get(Calendar.DAY_OF_MONTH);
            int hour = cal.get(Calendar.HOUR_OF_DAY);
            int minute = cal.get(Calendar.MINUTE);
            int second = cal.get(Calendar.SECOND);
            StringBuffer sb = new StringBuffer();
            sb.append(year).append("_").append(addzero(month, 2)).append("_")
                    .append(addzero(day, 2)).append("_").append(addzero(hour, 2))
                    .append("_").append(addzero(minute, 2)).append("_")
                    .append(addzero(second, 2));
            return sb.toString();
        }
    
        /**
         * 获得当前日期字符串,格式"yyyy-MM-dd HH:mm:ss"
         *
         * @return
         */
        public static String getNow() {
            Calendar today = Calendar.getInstance();
            return dateToString(today.getTime(), FORMAT_ONE);
        }
    
        /**
         * 获取当前时间
         *
         * @param strFormat --指定格式
         * @return
         */
        public static String getNow(String strFormat) {
            Calendar today = Calendar.getInstance();
            return dateToString(today.getTime(), strFormat);
        }
    
        /**
         * 判断日期是否有效,包括闰年的情况
         *
         * @param date YYYY-mm-dd
         * @return
         */
        public static boolean isDate(String date) {
            StringBuffer reg = new StringBuffer(
                    "^((\\d{2}(([02468][048])|([13579][26]))-?((((0?");
            reg.append("[13578])|(1[02]))-?((0?[1-9])|([1-2][0-9])|(3[01])))");
            reg.append("|(((0?[469])|(11))-?((0?[1-9])|([1-2][0-9])|(30)))|");
            reg.append("(0?2-?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][12");
            reg.append("35679])|([13579][01345789]))-?((((0?[13578])|(1[02]))");
            reg.append("-?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))");
            reg.append("-?((0?[1-9])|([1-2][0-9])|(30)))|(0?2-?((0?[");
            reg.append("1-9])|(1[0-9])|(2[0-8]))))))");
            Pattern p = Pattern.compile(reg.toString());
            return p.matcher(date).matches();
        }
    
        /**
         * 取得指定日期过 months 月后的日期 (当 months 为负数表示指定月之前);
         *
         * @param date   日期 为null时表示当天
         * @param months 相加(相减)的月数
         */
        public static Date nextMonth(Date date, int months) {
            Calendar cal = Calendar.getInstance();
            if (date != null) {
                cal.setTime(date);
            }
            cal.add(Calendar.MONTH, months);
            return cal.getTime();
        }
    
        /**
         * 取得指定日期过 day 天后的日期 (当 day 为负数表示指日期之前);
         *
         * @param date 日期 为null时表示当天
         */
        public static Date nextDay(Date date, int day) {
    
            Calendar cal = Calendar.getInstance();
            if (date != null) {
                cal.setTime(date);
            }
            cal.add(Calendar.DAY_OF_YEAR, day);
            return cal.getTime();
        }
    
        /**
         * 取得距离今天 day 日的日期
         *
         * @param day
         * @param format
         * @return
         * @author chenyz
         */
        public static String nextDay(int day, String format) {
            Calendar cal = Calendar.getInstance();
            cal.setTime(new Date());
            cal.add(Calendar.DAY_OF_YEAR, day);
            return dateToString(cal.getTime(), format);
        }
    
        /**
         * 取得指定日期过 day 周后的日期 (当 day 为负数表示指定月之前)
         *
         * @param date 日期 为null时表示当天
         */
        public static Date nextWeek(Date date, int week) {
            Calendar cal = Calendar.getInstance();
            if (date != null) {
                cal.setTime(date);
            }
            cal.add(Calendar.WEEK_OF_MONTH, week);
            return cal.getTime();
        }
    
        /**
         * 获取当前的日期(yyyy-MM-dd)
         */
        public static String currDay() {
            return DateUtils.dateToString(new Date(), DateUtils.LONG_DATE_FORMAT);
        }
    
        /**
         * 获取昨天的日期
         *
         * @return
         */
        public static String befoDay() {
            return befoDay(DateUtils.LONG_DATE_FORMAT);
        }
    
        /**
         * 根据时间类型获取昨天的日期
         *
         * @param format
         * @return
         * @author chenyz
         */
        public static String befoDay(String format) {
            return DateUtils.dateToString(DateUtils.nextDay(new Date(), -1), format);
        }
    
        /**
         * 获取明天的日期
         */
        public static String tomorrowDay() {
            return DateUtils.dateToString(DateUtils.nextDay(new Date(), 1),
                    DateUtils.LONG_DATE_FORMAT);
        }
    
        /**
         * 获取明天的日期(yyyy-mm-dd hh:mm:ss)
         */
        public static String tomorrowDayTime() {
            return nextDay(1, DateUtils.FORMAT_ONE);
        }
    
        /**
         * 获取后天的日期(yyyy-mm-dd hh:mm:ss)
         */
        public static String afterDayTime() {
            return nextDay(2, DateUtils.FORMAT_ONE);
        }
    
        /**
         * 取得当前时间距离1900/1/1的天数
         *
         * @return
         */
        public static int getDayNum() {
            int daynum = 0;
            GregorianCalendar gd = new GregorianCalendar();
            Date dt = gd.getTime();
            GregorianCalendar gd1 = new GregorianCalendar(1900, 1, 1);
            Date dt1 = gd1.getTime();
            daynum = (int) ((dt.getTime() - dt1.getTime()) / (24 * 60 * 60 * 1000));
            return daynum;
        }
    
        /**
         * getDayNum的逆方法(用于处理Excel取出的日期格式数据等)
         *
         * @param day
         * @return
         */
        public static Date getDateByNum(int day) {
            GregorianCalendar gd = new GregorianCalendar(1900, 1, 1);
            Date date = gd.getTime();
            date = nextDay(date, day);
            return date;
        }
    
        /**
         * 针对yyyy-MM-dd HH:mm:ss格式,显示yyyymmdd
         */
        public static String getYmdDateCN(String datestr) {
            if (datestr == null)
                return "";
            if (datestr.length() < 10)
                return "";
            StringBuffer buf = new StringBuffer();
            buf.append(datestr.substring(0, 4)).append(datestr.substring(5, 7))
                    .append(datestr.substring(8, 10));
            return buf.toString();
        }
    
        /**
         * 获取本月第一天
         *
         * @param format
         * @return
         */
        public static String getFirstDayOfMonth(String format) {
            Calendar cal = Calendar.getInstance();
            cal.set(Calendar.DATE, 1);
            return dateToString(cal.getTime(), format);
        }
    
        /**
         * 获取某月第一天
         *
         * @param iDate
         * @param format
         * @return
         */
        public static String getFirstDayOfMonth(Date iDate, String format) {
            Calendar cal = Calendar.getInstance();
            cal.setTime(iDate);
            cal.set(Calendar.DATE, 1);
            return dateToString(cal.getTime(), format);
        }
    
        /**
         * 获取本月最后一天
         *
         * @param format
         * @return
         */
        public static String getLastDayOfMonth(String format) {
            Calendar cal = Calendar.getInstance();
            cal.set(Calendar.DATE, 1);
            cal.add(Calendar.MONTH, 1);
            cal.add(Calendar.DATE, -1);
            return dateToString(cal.getTime(), format);
        }
    
        /**
         * 获取某月最后一天
         *
         * @param format
         * @return
         */
        public static String getLastDayOfMonth(Date iDate, String format) {
            Calendar cal = Calendar.getInstance();
            cal.setTime(iDate);
            cal.set(Calendar.DATE, 1);
            cal.add(Calendar.MONTH, 1);
            cal.add(Calendar.DATE, -1);
            return dateToString(cal.getTime(), format);
        }
    
        /**
         * 将元数据前补零,补后的总长度为指定的长度,以字符串的形式返回
         *
         * @param sourceDate
         * @param formatLength
         * @return 重组后的数据
         */
        public static String addzero(int sourceDate, int formatLength) {
            /*
             * 0 指前面补充零 formatLength 字符总长度为 formatLength d 代表为正数。
             */
            String newString = String.format("%0" + formatLength + "d", sourceDate);
            return newString;
        }
    
        /**
         * 判断是否在2个时间点内
         *
         * @param iStartDate  开始时间
         * @param iEndDate    结束时间
         * @param iSelectDate 选择的时间
         * @return
         */
        public static Boolean isTimeQuantum(String iStartDate, String iEndDate,
                                            String iSelectDate) {
            int startDiff = yearDiff(iStartDate, iSelectDate);
            int endDiff = yearDiff(iSelectDate, iEndDate);
            if (startDiff >= 0 && endDiff > 0) {
                return true;
            } else {
                return false;
            }
        }
    
        public static final Date str2Date(String aMask, String strDate)
                throws ParseException {
            SimpleDateFormat df = null;
            Date date = null;
            df = new SimpleDateFormat(aMask);
    
            try {
                date = df.parse(strDate);
            } catch (ParseException pe) {
                return null;
            } catch (java.text.ParseException e) {
                // TODO 自动生成的 catch 块
                e.printStackTrace();
            }
    
            return (date);
        }
    
        public static final String date2Str(Date aDate) {
            SimpleDateFormat df = null;
            String returnValue = "";
    
            if (aDate != null) {
                df = new SimpleDateFormat(datePattern);
                returnValue = df.format(aDate);
            }
    
            return (returnValue);
        }
    
        public static final String date2Str(String pattern, Date aDate) {
            SimpleDateFormat df = null;
            String returnValue = "";
    
            if (aDate != null) {
                df = new SimpleDateFormat(pattern);
                returnValue = df.format(aDate);
            }
            return (returnValue);
        }
    
        // 日期格式转换成时间戳
        public static long getTimeStamp(String pattern, String strDate) {
            long returnTimeStamp = 0;
            Date aDate = null;
            try {
                aDate = convertStringToDate(pattern, strDate);
            } catch (ParseException pe) {
                aDate = null;
            }
            if (aDate == null) {
                returnTimeStamp = 0;
            } else {
                returnTimeStamp = aDate.getTime();
            }
            return returnTimeStamp;
        }
    
        /**
         * This method converts a String to a date using the datePattern
         *
         * @param strDate the date to convert (in format MM/dd/yyyy)
         * @return a date object
         * @throws ParseException
         */
        public static Date convertStringToDate(String strDate)
                throws ParseException {
            Date aDate = null;
    
            try {
    
                aDate = convertStringToDate(datePattern, strDate);
            } catch (ParseException pe) {
                // log.error("Could not convert '" + strDate
                // + "' to a date, throwing exception");
                pe.printStackTrace();
                return null;
    
            }
            return aDate;
        }
    
        /**
         * This method generates a string representation of a date/time in the
         * format you specify on input
         *
         * @param aMask   the date pattern the string is in
         * @param strDate a string representation of a date
         * @return a converted Date object
         * @throws ParseException
         * @see SimpleDateFormat
         */
        public static final Date convertStringToDate(String aMask, String strDate)
                throws ParseException {
            SimpleDateFormat df = null;
            Date date = null;
            df = new SimpleDateFormat(aMask);
    
            try {
                date = df.parse(strDate);
            } catch (ParseException pe) {
                return null;
            } catch (java.text.ParseException e) {
                e.printStackTrace();
            }
    
            return (date);
        }
    
        /**
         * 时间戳格式转换
         */
        public static String getNewChatTime(long timesamp) {
            String result = "";
            Calendar todayCalendar = Calendar.getInstance();
            Calendar otherCalendar = Calendar.getInstance();
            otherCalendar.setTimeInMillis(timesamp);
    
            String timeFormat = "M月d日 HH:mm";
            String yearTimeFormat = "yyyy年M月d日 HH:mm";
    //        String am_pm = "";
    //        int hour = otherCalendar.get(Calendar.HOUR_OF_DAY);
    //        if (hour >= 0 && hour < 6) {
    //            am_pm = "凌晨";
    //        } else if (hour >= 6 && hour < 12) {
    //            am_pm = "早上";
    //        } else if (hour == 12) {
    //            am_pm = "中午";
    //        } else if (hour > 12 && hour < 18) {
    //            am_pm = "下午";
    //        } else if (hour >= 18) {
    //            am_pm = "晚上";g
    //        }
    //        timeFormat = "M月d日 " + am_pm + "HH:mm";
    //        yearTimeFormat = "yyyy年M月d日 " + am_pm + "HH:mm";
    
            timeFormat = "M月d日 " + "HH:mm";
            yearTimeFormat = "yyyy年M月d日 " + "HH:mm";
    
            boolean yearTemp = todayCalendar.get(Calendar.YEAR) == otherCalendar.get(Calendar.YEAR);
            if (yearTemp) {
                int todayMonth = todayCalendar.get(Calendar.MONTH);
                int otherMonth = otherCalendar.get(Calendar.MONTH);
                if (todayMonth == otherMonth) {//表示是同一个月
                    int temp = todayCalendar.get(Calendar.DATE) - otherCalendar.get(Calendar.DATE);
                    switch (temp) {
                        case 0:
                            result = getHourAndMin(timesamp);
                            break;
                        case 1:
                            result = "昨天 " + getHourAndMin(timesamp);
                            break;
                        case 2:
                        case 3:
                        case 4:
                        case 5:
                        case 6:
                            int dayOfMonth = otherCalendar.get(Calendar.WEEK_OF_MONTH);
                            int todayOfMonth = todayCalendar.get(Calendar.WEEK_OF_MONTH);
                            if (dayOfMonth == todayOfMonth) {//表示是同一周
                                int dayOfWeek = otherCalendar.get(Calendar.DAY_OF_WEEK);
                                if (dayOfWeek != 1) {//判断当前是不是星期日     如想显示为:周日 12:09 可去掉此判断
                                    result = dayNames[otherCalendar.get(Calendar.DAY_OF_WEEK) - 1] + getHourAndMin(timesamp);
                                } else {
                                    result = getTime(timesamp, timeFormat);
                                }
                            } else {
                                result = getTime(timesamp, timeFormat);
                            }
                            break;
                        default:
                            result = getTime(timesamp, timeFormat);
                            break;
                    }
                } else {
                    result = getTime(timesamp, timeFormat);
                }
            } else {
                result = getYearTime(timesamp, yearTimeFormat);
            }
            return result;
        }
    
        /**
         * 当天的显示时间格式
         *
         * @param time
         * @return
         */
        public static String getHourAndMin(long time) {
            SimpleDateFormat format = new SimpleDateFormat("HH:mm");
            return format.format(new Date(time));
        }
    
        /**
         * 不同一周的显示时间格式
         *
         * @param time
         * @param timeFormat
         * @return
         */
        public static String getTime(long time, String timeFormat) {
            SimpleDateFormat format = new SimpleDateFormat(timeFormat);
            return format.format(new Date(time));
        }
    
        /**
         * 不同年的显示时间格式
         *
         * @param time
         * @param yearTimeFormat
         * @return
         */
        public static String getYearTime(long time, String yearTimeFormat) {
            SimpleDateFormat format = new SimpleDateFormat(yearTimeFormat);
            return format.format(new Date(time));
        }
    
        /**
         * 秒换算为时分秒
         *
         * @param second
         * @return
         */
        public static String cal(int second) {
            int h = 0;
            int d = 0;
            int s = 0;
            int temp = second % 3600;
            if (second > 3600) {
                h = second / 3600;
                if (temp != 0) {
                    if (temp > 60) {
                        d = temp / 60;
                        if (temp % 60 != 0) {
                            s = temp % 60;
                        }
                    } else {
                        s = temp;
                    }
                }
            } else {
                d = second / 60;
                if (second % 60 != 0) {
                    s = second % 60;
                }
            }
            if (d == 0 && s < 10) return d + ":" + "0" + s;
            if (d == 0 && s > 10) return d + ":" + s;
            if (d < 10 && s < 10) return "0" + d + ":" + "0" + s;
            if (d < 10 && s > 10) return "0" + d + ":" + s;
            if (d > 10 && s > 10) return d + ":" + s;
            if (d > 10 && s < 10) return d + ":" + "0" + s;
            return d + ":" + s;
        }
    
        /**
         * 计算两个日期相差了几个月
         *
         * @param startDate
         * @param endDate
         * @return
         */
        public static int getMonthSub(String startDate, String endDate) {
            int count = 0;
            try {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
                Calendar bef = Calendar.getInstance();
                Calendar aft = Calendar.getInstance();
                bef.setTime(sdf.parse(startDate));
                aft.setTime(sdf.parse(endDate));
                int result = aft.get(Calendar.MONTH) - bef.get(Calendar.MONTH);
                int month = (aft.get(Calendar.YEAR) - bef.get(Calendar.YEAR)) * 12;
                count = Math.abs(month + result);
            } catch (java.text.ParseException e) {
                e.printStackTrace();
            }
            return count;
        }
    
        /**
         * 两个日期相减
         *
         * @param firstTime
         * @param secTime
         * @return 相减得到的秒数
         */
        public static long timeDaySub(String firstTime, String secTime) {
            long first = stringtoDate(firstTime, LONG_DATE_FORMAT).getTime();
            long second = stringtoDate(secTime, LONG_DATE_FORMAT).getTime();
            return (second - first) / 1000;
        }
    
        //当前时间是否在某一时间段内
        public static boolean isInPeriodOfTime(String beginTime, String endTime) {
            boolean isInTime = false;
            //获取当前系统时间
            Date currentTime = new Date();//currentTime就是系统当前时间
            Date strbeginDate = DateUtils.stringtoDate(beginTime, DateUtils.FORMAT_TWO);//起始时间
            Date strendDate = DateUtils.stringtoDate(endTime, DateUtils.FORMAT_TWO);//结束时间
    
            Calendar cal = Calendar.getInstance();
            if (strendDate != null) {
                cal.setTime(strendDate);
            }
            cal.add(Calendar.MINUTE, 20);
            strendDate = cal.getTime();
    
            if ((currentTime.getTime() - strbeginDate.getTime()) >= 0 && (strendDate.getTime() - currentTime.getTime()) >= 0) {//使用.getTime方法把时间转化成毫秒数,然后进行比较
    
                isInTime = true;
            } else {
                isInTime = false;
            }
    
    
            return isInTime;
        }
    
        /**
         * 种子时间是否在某一时间段内
         *
         * @param beginTime 区间开始时间
         * @param endTime   区间结束时间
         * @param seedDate  种子时间
         * @return
         */
        public static boolean isInPeriodOfIntervalTime(String beginTime, String endTime, String seedDate) {
            boolean isInTime = false;
            try {
                //种子时间
                Date currentTime = DateUtils.stringtoDate(seedDate, DateUtils.DATE_FORMAT_YEAR_MONTH_DAY_HOUR_MIN_SECOND);
                //起始时间
                Date strbeginDate = DateUtils.stringtoDate(beginTime, DateUtils.DATE_FORMAT_YEAR_MONTH_DAY_HOUR_MIN);
                //结束时间
                Date strendDate = DateUtils.stringtoDate(endTime, DateUtils.DATE_FORMAT_YEAR_MONTH_DAY_HOUR_MIN);
                Calendar cal = Calendar.getInstance();
                if (strendDate != null) {
                    cal.setTime(strendDate);
                }
                cal.add(Calendar.MINUTE, 20);
                strendDate = cal.getTime();
                if ((currentTime.getTime() - strbeginDate.getTime()) >= 0 &&
                        (strendDate.getTime() - currentTime.getTime()) >= 0) {
                    //使用.getTime方法把时间转化成毫秒数,然后进行比较
                    isInTime = true;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return isInTime;
        }
    
        /**
         * 种子时间是否在某一时间段内
         *
         * @param beginTime 区间开始时间
         * @param endTime   区间结束时间
         * @param seedDate  种子时间
         * @return
         */
        public static boolean isInPeriodOfIntervalTime2(String beginTime, String endTime, String seedDate) {
            boolean isInTime = false;
            try {
                //种子时间
                Date currentTime = DateUtils.stringtoDate(seedDate, DateUtils.DATE_FORMAT_YEAR_MONTH_DAY_HOUR_MIN);
                //起始时间
                Date strbeginDate = DateUtils.stringtoDate(beginTime, DateUtils.DATE_FORMAT_YEAR_MONTH_DAY_HOUR_MIN);
                //结束时间
                Date strendDate = DateUtils.stringtoDate(endTime, DateUtils.DATE_FORMAT_YEAR_MONTH_DAY_HOUR_MIN);
                Calendar cal = Calendar.getInstance();
                if (strendDate != null) {
                    cal.setTime(strendDate);
                }
                cal.add(Calendar.MINUTE, 20);
                strendDate = cal.getTime();
                if ((currentTime.getTime() - strbeginDate.getTime()) >= 0 &&
                        (strendDate.getTime() - currentTime.getTime()) >= 0) {
                    //使用.getTime方法把时间转化成毫秒数,然后进行比较
                    isInTime = true;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return isInTime;
        }
    
        /**
         * 当前时间属于本月第几周
         *
         * @param dateString
         * @return
         */
        public static int getWeekOfMonth(String dateString, String startDate) {
            int weekOfMonth = 0;
            try {
                SimpleDateFormat sdf = new SimpleDateFormat(LONG_DATE_FORMAT);
                Date date = sdf.parse(dateString);
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(date);
                weekOfMonth = calendar.get(Calendar.WEEK_OF_MONTH);
                //获取当前时间为本周的第几天
                String[] mdate = startDate.split("-");
                if (mdate[2].equals("01")) {//本月第一天为周一
                } else {
                    weekOfMonth = weekOfMonth - 1;
                }
    
            } catch (java.text.ParseException e) {
                e.printStackTrace();
                return weekOfMonth;
            }
    
            return weekOfMonth;
        }
    
        public static String dateToWeek(String datetime) {
            SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
            String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
            Calendar cal = Calendar.getInstance();
            Date date = null;
            try {
                try {
                    date = f.parse(datetime);
                } catch (java.text.ParseException e) {
                    e.printStackTrace();
                }
                cal.setTime(date);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //一周的第几天
            int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
            if (w < 0)
                w = 0;
            return weekDays[w];
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296
    • 297
    • 298
    • 299
    • 300
    • 301
    • 302
    • 303
    • 304
    • 305
    • 306
    • 307
    • 308
    • 309
    • 310
    • 311
    • 312
    • 313
    • 314
    • 315
    • 316
    • 317
    • 318
    • 319
    • 320
    • 321
    • 322
    • 323
    • 324
    • 325
    • 326
    • 327
    • 328
    • 329
    • 330
    • 331
    • 332
    • 333
    • 334
    • 335
    • 336
    • 337
    • 338
    • 339
    • 340
    • 341
    • 342
    • 343
    • 344
    • 345
    • 346
    • 347
    • 348
    • 349
    • 350
    • 351
    • 352
    • 353
    • 354
    • 355
    • 356
    • 357
    • 358
    • 359
    • 360
    • 361
    • 362
    • 363
    • 364
    • 365
    • 366
    • 367
    • 368
    • 369
    • 370
    • 371
    • 372
    • 373
    • 374
    • 375
    • 376
    • 377
    • 378
    • 379
    • 380
    • 381
    • 382
    • 383
    • 384
    • 385
    • 386
    • 387
    • 388
    • 389
    • 390
    • 391
    • 392
    • 393
    • 394
    • 395
    • 396
    • 397
    • 398
    • 399
    • 400
    • 401
    • 402
    • 403
    • 404
    • 405
    • 406
    • 407
    • 408
    • 409
    • 410
    • 411
    • 412
    • 413
    • 414
    • 415
    • 416
    • 417
    • 418
    • 419
    • 420
    • 421
    • 422
    • 423
    • 424
    • 425
    • 426
    • 427
    • 428
    • 429
    • 430
    • 431
    • 432
    • 433
    • 434
    • 435
    • 436
    • 437
    • 438
    • 439
    • 440
    • 441
    • 442
    • 443
    • 444
    • 445
    • 446
    • 447
    • 448
    • 449
    • 450
    • 451
    • 452
    • 453
    • 454
    • 455
    • 456
    • 457
    • 458
    • 459
    • 460
    • 461
    • 462
    • 463
    • 464
    • 465
    • 466
    • 467
    • 468
    • 469
    • 470
    • 471
    • 472
    • 473
    • 474
    • 475
    • 476
    • 477
    • 478
    • 479
    • 480
    • 481
    • 482
    • 483
    • 484
    • 485
    • 486
    • 487
    • 488
    • 489
    • 490
    • 491
    • 492
    • 493
    • 494
    • 495
    • 496
    • 497
    • 498
    • 499
    • 500
    • 501
    • 502
    • 503
    • 504
    • 505
    • 506
    • 507
    • 508
    • 509
    • 510
    • 511
    • 512
    • 513
    • 514
    • 515
    • 516
    • 517
    • 518
    • 519
    • 520
    • 521
    • 522
    • 523
    • 524
    • 525
    • 526
    • 527
    • 528
    • 529
    • 530
    • 531
    • 532
    • 533
    • 534
    • 535
    • 536
    • 537
    • 538
    • 539
    • 540
    • 541
    • 542
    • 543
    • 544
    • 545
    • 546
    • 547
    • 548
    • 549
    • 550
    • 551
    • 552
    • 553
    • 554
    • 555
    • 556
    • 557
    • 558
    • 559
    • 560
    • 561
    • 562
    • 563
    • 564
    • 565
    • 566
    • 567
    • 568
    • 569
    • 570
    • 571
    • 572
    • 573
    • 574
    • 575
    • 576
    • 577
    • 578
    • 579
    • 580
    • 581
    • 582
    • 583
    • 584
    • 585
    • 586
    • 587
    • 588
    • 589
    • 590
    • 591
    • 592
    • 593
    • 594
    • 595
    • 596
    • 597
    • 598
    • 599
    • 600
    • 601
    • 602
    • 603
    • 604
    • 605
    • 606
    • 607
    • 608
    • 609
    • 610
    • 611
    • 612
    • 613
    • 614
    • 615
    • 616
    • 617
    • 618
    • 619
    • 620
    • 621
    • 622
    • 623
    • 624
    • 625
    • 626
    • 627
    • 628
    • 629
    • 630
    • 631
    • 632
    • 633
    • 634
    • 635
    • 636
    • 637
    • 638
    • 639
    • 640
    • 641
    • 642
    • 643
    • 644
    • 645
    • 646
    • 647
    • 648
    • 649
    • 650
    • 651
    • 652
    • 653
    • 654
    • 655
    • 656
    • 657
    • 658
    • 659
    • 660
    • 661
    • 662
    • 663
    • 664
    • 665
    • 666
    • 667
    • 668
    • 669
    • 670
    • 671
    • 672
    • 673
    • 674
    • 675
    • 676
    • 677
    • 678
    • 679
    • 680
    • 681
    • 682
    • 683
    • 684
    • 685
    • 686
    • 687
    • 688
    • 689
    • 690
    • 691
    • 692
    • 693
    • 694
    • 695
    • 696
    • 697
    • 698
    • 699
    • 700
    • 701
    • 702
    • 703
    • 704
    • 705
    • 706
    • 707
    • 708
    • 709
    • 710
    • 711
    • 712
    • 713
    • 714
    • 715
    • 716
    • 717
    • 718
    • 719
    • 720
    • 721
    • 722
    • 723
    • 724
    • 725
    • 726
    • 727
    • 728
    • 729
    • 730
    • 731
    • 732
    • 733
    • 734
    • 735
    • 736
    • 737
    • 738
    • 739
    • 740
    • 741
    • 742
    • 743
    • 744
    • 745
    • 746
    • 747
    • 748
    • 749
    • 750
    • 751
    • 752
    • 753
    • 754
    • 755
    • 756
    • 757
    • 758
    • 759
    • 760
    • 761
    • 762
    • 763
    • 764
    • 765
    • 766
    • 767
    • 768
    • 769
    • 770
    • 771
    • 772
    • 773
    • 774
    • 775
    • 776
    • 777
    • 778
    • 779
    • 780
    • 781
    • 782
    • 783
    • 784
    • 785
    • 786
    • 787
    • 788
    • 789
    • 790
    • 791
    • 792
    • 793
    • 794
    • 795
    • 796
    • 797
    • 798
    • 799
    • 800
    • 801
    • 802
    • 803
    • 804
    • 805
    • 806
    • 807
    • 808
    • 809
    • 810
    • 811
    • 812
    • 813
    • 814
    • 815
    • 816
    • 817
    • 818
    • 819
    • 820
    • 821
    • 822
    • 823
    • 824
    • 825
    • 826
    • 827
    • 828
    • 829
    • 830
    • 831
    • 832
    • 833
    • 834
    • 835
    • 836
    • 837
    • 838
    • 839
    • 840
    • 841
    • 842
    • 843
    • 844
    • 845
    • 846
    • 847
    • 848
    • 849
    • 850
    • 851
    • 852
    • 853
    • 854
    • 855
    • 856
    • 857
    • 858
    • 859
    • 860
    • 861
    • 862
    • 863
    • 864
    • 865
    • 866
    • 867
    • 868
    • 869
    • 870
    • 871
    • 872
    • 873
    • 874
    • 875
    • 876
    • 877
    • 878
    • 879
    • 880
    • 881
    • 882
    • 883
    • 884
    • 885
    • 886
    • 887
    • 888
    • 889
    • 890
    • 891
    • 892
    • 893
    • 894
    • 895
    • 896
    • 897
    • 898
    • 899
    • 900
    • 901
    • 902
    • 903
    • 904
    • 905
    • 906
    • 907
    • 908
    • 909
    • 910
    • 911
    • 912
    • 913
    • 914
    • 915
    • 916
    • 917
    • 918
    • 919
    • 920
    • 921
    • 922
    • 923
    • 924
    • 925
    • 926
    • 927
    • 928
    • 929
    • 930
    • 931
    • 932
    • 933
    • 934
    • 935
    • 936
    • 937
    • 938
    • 939
    • 940
    • 941
    • 942
    • 943
    • 944
    • 945
    • 946
    • 947
    • 948
    • 949
    • 950
    • 951
    • 952
    • 953
    • 954
    • 955
    • 956
    • 957
    • 958
    • 959
    • 960
    • 961
    • 962
    • 963
    • 964
    • 965
    • 966
    • 967
    • 968
    • 969
    • 970
    • 971
    • 972
    • 973
    • 974
    • 975
    • 976
    • 977
    • 978
    • 979
    • 980
    • 981
    • 982
    • 983
    • 984
    • 985
    • 986
    • 987
    • 988
    • 989
    • 990
    • 991
    • 992
    • 993
    • 994
    • 995
    • 996
    • 997
    • 998
    • 999
    • 1000
    • 1001
    • 1002
    • 1003
    • 1004
    • 1005
    • 1006
    • 1007
    • 1008
    • 1009
    • 1010
    • 1011
    • 1012
    • 1013
    • 1014
    • 1015
    • 1016
    • 1017
    • 1018
    • 1019
    • 1020
    • 1021
    • 1022
    • 1023
    • 1024
    • 1025
    • 1026
    • 1027
    • 1028
    • 1029
    • 1030
    • 1031
    • 1032
    • 1033
    • 1034
    • 1035
    • 1036
    • 1037
    • 1038
    • 1039
    • 1040
    • 1041
    • 1042
    • 1043
    • 1044
    • 1045
    • 1046
    • 1047
    • 1048
    • 1049
    • 1050
    • 1051
    • 1052
    • 1053
    • 1054
    • 1055
    • 1056
    • 1057
    • 1058
    • 1059
    • 1060
    • 1061
    • 1062
    • 1063
    • 1064
    • 1065
    • 1066
    • 1067
    • 1068
    • 1069
    • 1070
    • 1071
    • 1072
    • 1073
    • 1074
    • 1075
    • 1076
    • 1077
    • 1078
    • 1079
    • 1080
    • 1081
    • 1082
    • 1083
    • 1084
    • 1085
    • 1086
    • 1087
    • 1088
    • 1089
    • 1090
    • 1091
    • 1092
    • 1093
    • 1094
    • 1095
    • 1096
    • 1097
    • 1098
    • 1099
    • 1100
    • 1101
    • 1102
    • 1103
    • 1104
    • 1105
    • 1106
    • 1107
    • 1108
    • 1109
    • 1110
    • 1111
    • 1112
    • 1113
    • 1114
    • 1115
    • 1116
    • 1117
    • 1118
    • 1119
    • 1120
    • 1121
    • 1122
    • 1123
    • 1124
    • 1125
    • 1126
    • 1127
    • 1128
    • 1129
    • 1130
    • 1131
    • 1132
    • 1133
    • 1134
    • 1135
    • 1136
    • 1137
    • 1138
    • 1139
    • 1140
    • 1141
    • 1142
    • 1143
    • 1144
    • 1145
    • 1146
    • 1147
    • 1148
    • 1149
    • 1150
    • 1151
    • 1152
    • 1153
    • 1154
    • 1155
    • 1156
    • 1157
    • 1158
    • 1159
    • 1160
    • 1161
    • 1162
    • 1163
    • 1164
    • 1165
    • 1166
    • 1167
    • 1168
    • 1169
    • 1170
    • 1171
    • 1172
    • 1173
    • 1174
    • 1175
    • 1176
    • 1177
    • 1178
    • 1179
    • 1180
    • 1181
    • 1182
    • 1183
    • 1184
    • 1185
    • 1186
    • 1187
    • 1188
    • 1189
    • 1190
    • 1191
    • 1192
    • 1193
    • 1194
    • 1195
    • 1196
    • 1197
    • 1198
    • 1199
    • 1200
    • 1201
    • 1202
    • 1203
    • 1204
    • 1205
    • 1206
    • 1207
    • 1208
    • 1209
    • 1210
    • 1211
    • 1212
    • 1213
    • 1214
    • 1215
    • 1216
    • 1217
    • 1218
    • 1219
    • 1220
    • 1221
    • 1222
    • 1223
    • 1224
    • 1225
    • 1226
    • 1227
    • 1228
    • 1229
    • 1230
    • 1231
    • 1232
    • 1233
    • 1234
    • 1235
    • 1236
    • 1237
    • 1238
    • 1239
    • 1240
    • 1241
    • 1242
    • 1243
    • 1244
    • 1245
    • 1246
    • 1247
    • 1248
    • 1249
    • 1250
    • 1251
    • 1252
    • 1253
    • 1254
    • 1255
    • 1256
    • 1257
    • 1258
    • 1259
    • 1260
    • 1261
    • 1262
    • 1263
    • 1264
    • 1265
    • 1266
    • 1267
    • 1268
    • 1269
    • 1270
    • 1271
    • 1272
    • 1273
    • 1274
    • 1275
    • 1276
    • 1277
    • 1278
    • 1279
    • 1280
    • 1281
    • 1282
    • 1283
    • 1284
    • 1285
    • 1286
    • 1287
    • 1288
    • 1289
    • 1290
    • 1291
    • 1292
    • 1293
    • 1294
    • 1295
    • 1296
    • 1297
    • 1298
    • 1299
    • 1300
    • 1301
    • 1302
    • 1303
    • 1304
    • 1305
    • 1306
    • 1307
    • 1308
    • 1309
    • 1310
    • 1311
    • 1312
    • 1313
    • 1314
    • 1315
    • 1316
    • 1317
    • 1318
    • 1319
    • 1320
    • 1321
    • 1322
    • 1323
    • 1324
    • 1325
    • 1326
    • 1327
    • 1328
    • 1329
    • 1330
    • 1331
    • 1332
    • 1333
    • 1334
    • 1335
    • 1336
    • 1337
    • 1338
    • 1339
    • 1340
    • 1341
    • 1342
    • 1343
    • 1344
    • 1345
    • 1346
    • 1347
    • 1348
    • 1349
    • 1350
    • 1351
    • 1352
    • 1353
    • 1354
    • 1355
    • 1356
    • 1357
    • 1358
    • 1359
    • 1360
    • 1361
    • 1362
    • 1363
    • 1364
    • 1365
    • 1366
    • 1367
    • 1368
    • 1369
    • 1370
    • 1371
    • 1372
    • 1373
    • 1374
    • 1375
    • 1376
    • 1377
    • 1378
    • 1379
    • 1380
    • 1381
    • 1382
    • 1383
    • 1384
    • 1385
    • 1386
    • 1387
    • 1388
    • 1389
    • 1390
    • 1391
    • 1392
    • 1393
    • 1394
    • 1395

    R.layout.item_month

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:background="#ffffff"
        android:layout_height="50dp">
    
        <TextView
            android:id="@+id/tv_month"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:padding="5dp"
            android:text="8"
            android:textSize="15dp"
            android:textColor="#ff6600" />
    
    </androidx.constraintlayout.widget.ConstraintLayout>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    R.layout.item_day

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
        android:background="#ffffff">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:orientation="vertical">
    
            <TextView
                android:id="@+id/tv_day"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:gravity="center"
                android:text="1"
                android:textSize="15dp" />
    
        </LinearLayout>
    
    </RelativeLayout>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26

    OK!到这里就结束了 有什么问题可以发布评论一起探讨下

  • 相关阅读:
    Golang每日一练(leetDay0075) 打家劫舍II、最短回文串
    使用ControlCAN.dll收发报文功能实现诊断仪与硬件的UDS报文交互
    博纳影业明日上市:于冬陷入与江疏影绯闻 被曝斥资千万买珠宝
    【web渗透】XSS跨站请求攻击
    大模型的实践应用7-阿里的多版本通义千问Qwen大模型的快速应用与部署
    CUDA编程基础:如何实现c++事实绘制曲线,采用的绘图工具箱是:gnuplot
    R语言将dataframe中的多个数据列相加形成新的向量、并将生成的向量并入dataframe中
    Mysql字符集和排序规则
    【.NET深呼吸】用代码写WPF控件模板
    Leetcode: 645.错误的集合 题解【超详细】
  • 原文地址:https://blog.csdn.net/yuhang01/article/details/126345468