public class TestDate {
		
		
				
						 
				
		
		
				
						       public String yesteday() {
		
		
				
						              
//           当前时间
               Calendar cal = Calendar.getInstance();
		
		
				
						           //  日期的DATE减去10  就是往后推10 天 同理 +10 就是往后推十天
              cal.add(Calendar.DATE, -10);
		
		
				
						 
				
		
		
				
						              SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
		
		
				
						             
				
		
		
				
						              String str = sf.format(cal.getTime());
		
		
				
						              
						
						
				
		
		
				
						              System.out.print(str);
		
		
				
						              return str;
		
		
				
						       }
		
		
				
						 
				
		
		
				
						       public static void main(String args[]) {
		
		
				
						              new TestDate().yesteday();
		
		
				
						       }
		
		
				
						 
				
		
		
				}
		
		
				
				
记的用DATE 类的时候要先得到当前的年,月,日,再将日数减或加.再new Date(year,month,day);
有了 Calendar 感觉方便多了. 
	posted on 2006-03-18 07:52 
square 阅读(2768) 
评论(1)  编辑  收藏