• 获取时间段的工具类(一般用于匹配数据库查询)


    /**
         * 获取指定日期的工具方法
         */
        public Map<String,Object> getStartAndEndTime(String timeType){
            String startTime="";
            String endTime="";
            Calendar cal=Calendar.getInstance();
            String today = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
            String todayDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
            switch (timeType) {
                case "1"://今日
                    startTime=today+" 00:00:00";
                    endTime=today+" 23:59:59";
                    break;
                case "2"://昨日
                    cal.add(Calendar.DATE,-1);
                    String yesToday = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
                    startTime=yesToday+" 00:00:00";
                    endTime=yesToday+" 23:59:59";
                    break;
                case "3"://近7天
                    cal.add(Calendar.DATE,-6);
                    String sevenDay = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
                    startTime=sevenDay+" 00:00:00";
                    endTime=today+" 23:59:59";
                    break;
                case "4"://近30天
                    cal.add(Calendar.DATE,-29);
                    String thirtyDay = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
                    startTime=thirtyDay+" 00:00:00";
                    endTime=today+" 23:59:59";
                    break;
                case "5"://本月
                    cal.add(Calendar.MONTH, 0);
                    cal.set(Calendar.DAY_OF_MONTH, 1);
                    String thisMonthFirstDay = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
                    startTime=thisMonthFirstDay+" 00:00:00";
                    endTime=today+" 23:59:59";
                    break;
                case "6"://本月截止当前时间
                    cal.add(Calendar.MONTH, 0);
                    cal.set(Calendar.DAY_OF_MONTH, 1);
                    String thisMonthFirstDay1 = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
                    startTime=thisMonthFirstDay1+" 00:00:00";
                    endTime=todayDate;
                    break;
                case "7"://上月
                    cal.set(Calendar.DAY_OF_MONTH, 0);
                    String lastMonthEndtDay = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
                    cal.set(Calendar.DAY_OF_MONTH, 1);
                    String lastMonthFirstDay = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
                    startTime=lastMonthFirstDay+" 00:00:00";
                    endTime=lastMonthEndtDay+" 23:59:59";
                    break;
                default:
                    startTime=null;
                    endTime=null;
                    break;
            }
            Map<String,Object> turnMap=new HashMap<String,Object>();
            turnMap.put("startTime",startTime);
            turnMap.put("endTime",endTime);
            return turnMap;
        }
    
  • 相关阅读:
    SQL命令
    MySQL、Oracle、SQL Server
    函数调用
    php 读取图片显示在页面上 demo
    浅谈PHP正则表达式中修饰符/i, /is, /s, /isU
    jquery $.ajax()方法
    HTML 字符实体
    php 内置支持的标签和属性
    java-03 变量与运算符
    java-02 JDK安装与环境变量配置&安装编程IDE
  • 原文地址:https://www.cnblogs.com/wtao0730/p/14693904.html
Copyright © 2020-2023  润新知