zoukankan      html  css  js  c++  java
  • 整理日期,整理时间段,将日期集合整理为时间段

    /**
         * 根据传入的日期集合  整理成时间段
         */
        public static String getDayToTimeSlot(List<String> list){
            String time="";
    
           Collections.sort(list, new Comparator<String>() {
               @Override
               public int compare(String o1, String o2) {
                   if(compareDate(o1,o2)){
                       return 1;
                   }
                   return -1;
               }
           });
            String time1="";
            String time2="";
           for(int i=0;i<list.size();i++){
               if(i==0){
                   time1=list.get(i);
                   time2=list.get(i);
               }
                if(i+1<list.size()){
                    if(getAfterDayDate(list.get(i),"1").equals(list.get(i+1))){
                        time2=list.get(i+1);
    
                    }else{
                        time+=time1+""+time2+",";
                        time1=list.get(i+1);
                        time2=list.get(i+1);
    
                    }
                }else{
                        if(i==0){
                            time+=time1+""+time2+",";
                        }else{
                            if(getAfterDayDate(list.get(i-1),"1").equals(list.get(i))){
                                time+=time1+""+time2+",";
                            }else{
                                time+=time2+""+time2+",";
                            }
                        }
    
    
                }
    
    
           }
    
    
            return time;
        }
        /**
         * 得到当前时间n天之后的日期
         *
         * @param days
         * @return
         */
        public static String getAfterDayDate(String time, String days) {
            int daysInt = Integer.parseInt(days);
            Calendar canlendar = Calendar.getInstance(); // java.util包
            Date date = fomatDate(time);
            canlendar.setTime(date);
            canlendar.add(Calendar.DATE, daysInt); // 日期减 如果不够减会将月变动
            Date time2 = canlendar.getTime();
            if(time.length()>=12){
                SimpleDateFormat sdfd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                String dateStr = sdfd.format(time2);
                return dateStr;
            }else{
                SimpleDateFormat sdfd = new SimpleDateFormat("yyyy-MM-dd");
                String dateStr = sdfd.format(time2);
                return dateStr;
            }
    
        }
  • 相关阅读:
    「日常报错」Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
    LeetCode1026. 节点与其祖先之间的最大差值
    Erlang TCP 实例
    「笔记」Systemd 的基础
    折腾日记「乱七八糟的过程」
    LeetCode15.三数之和
    Sql Paging
    行变列
    SQL JOINS
    DBML存储过程返回值
  • 原文地址:https://www.cnblogs.com/qq376324789/p/12867919.html
Copyright © 2011-2022 走看看