首页 > 代码库 > 获取昨天,前天,日期字符串

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

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;
}

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