Date中过期方法的替代品

  SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-dd");
  
  Date date = new Date ();
  int h = date.getDate () - 7;
  date.setDate (h);
  System.out.println(formatter.format (date.getTime ()));
  
  Calendar cd = Calendar.getInstance();
  cd.setTime(new Date());  
  cd.add(Calendar.DAY_OF_MONTH, -7);  
  System.out.println(formatter.format (cd.getTimeInMillis ()));

 

 

 

你可能感兴趣的:(Date)