java获取字符串格式日期向前或向后n天的日期

private void setTilteMessage(){ 
        BaseDao dao = new BaseDao(); 
        String titleData = dao.getLatestData(); 
        dao.closeDB(); 
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 
        try
            Date date = sdf.parse(titleData); 
            Calendar   calendar   =   new   GregorianCalendar();  
            calendar.setTime(date);  
            calendar.add(calendar.DATE,1);//把日期往后增加一天.整数往后推,负数往前移动  
            date=calendar.getTime();   //这个时间就是日期往后推一天的结果  
            String putDate = sdf.format(date); //增加一天后的日期 
               
        } catch (ParseException e) { 
            e.printStackTrace(); 
        
    }
posted @ 2016-02-22 13:14  mingli  阅读(2821)  评论(0编辑  收藏  举报