获取昨天,前天,日期字符串

public static String getYesterdayStr(){
  String yesterday=null;
  Calendar calendar = Calendar.getInstance();//此时获取的是系统当前时间
  calendar.add(Calendar.DATE, -1); //得到前一天
  yesterday= new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
  //System.out.println(yesterday);
  return yesterday;
}

public static String getBeforeYesterdayStr(){
  String beforeyesterday=null;
  Calendar calendar = Calendar.getInstance();//此时获取的是系统当前时间
  calendar.add(Calendar.DATE, -2); 
  beforeyesterday= new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
  //System.out.println(yesterday);
  return beforeyesterday;
}

posted @ 2017-04-25 17:40  静心jx  阅读(519)  评论(0编辑  收藏  举报