首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

获取当天日期跟前一天日期

2013-12-15 
获取当天日期和前一天日期/*** 获取当前时间* @return*/private String getCurrtime(String str){String s

获取当天日期和前一天日期
/** * 获取当前时间 * @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;}

?

热点排行