java 获取昨天日期

http://blog.sina.com.cn/s/blog_6d416c1e01019zod.html
1:Date as = new Date(new Date().getTime()-24*60*60*1000);
  SimpleDateFormat matter1 = new SimpleDateFormat("yyyy-MM-dd");
  String time = matter1.format(as);
  System.out.println(time);

  取出数字型的时间  再减去24*60*60*1000,就得到昨天的时间了;

这个有点过时了!

2:Calendar   cal   =   Calendar.getInstance();
  cal.add(Calendar.DATE,   -1);
  String yesterday = new SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime());
  System.out.println(yesterday);

这个方法很方便,年月日都可以随心所欲的变!

3,用apache的DateUtils( 需要 import org.apache.commons.lang.time.DateUtils;)

Date currentTime = AppUtils.getCurrentDate();
  //获取昨天时间
  Date backupTime=DateUtils.addDays(currentTime, -1);



4.sql 查询条件包含时间的处理方法:

select * from TBIMC1 where CREATE_DATE_<to_date( to_char(sysdate-1,'yyyy-mm-dd'),'yyyy-mm-dd')

你可能感兴趣的:(java)