获取当天日期和前一天日期
/** * 获取当前时间 * @return */private String getCurrtime(String str){String str_Time= "";Timestamp currentTime = new Timestamp(System.currentTimeMillis());//用calendar获取当天Calendar current = Calendar.getInstance();current.get(Calendar.YEAR);current.get(Calendar.MARCH + 1);current.set(Calendar.DAY_OF_MONTH, current.get(Calendar.DAY_OF_MONTH));Date currTime = current.getTime();SimpleDateFormat f=null;// 取前一天Calendar calendar = Calendar.getInstance();calendar.get(Calendar.YEAR);calendar.get(Calendar.MARCH + 1);calendar.set(Calendar.DAY_OF_MONTH, (calendar.get(Calendar.DAY_OF_MONTH) - 1));Date beforetime = calendar.getTime();if("beforeDay".equals(str)){SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmm");str_Time = df.format(beforetime);}else if("tdBatchBefore".equals(str)){SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");str_Time = df.format(beforetime);}else{if("batch".equals(str)){f = new SimpleDateFormat("yyMMddHHmm");}else if("today".equals(str)){f = new SimpleDateFormat("yyyyMMddHHmm");}else if("istoday".equals(str)){f=new SimpleDateFormat("yyyy-MM-dd");}str_Time = f.format(currTime);}return str_Time;}
?