1. 程式人生 > >java獲取前一天的日期方法

java獲取前一天的日期方法

public static void main(String[] args) {
Date date=new Date();
//Calendar calendar =new GregorianCalendar();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(calendar.DATE, -1);
date = calendar.getTime();
SimpleDateFormat format= new SimpleDateFormat("yyyy-MM-dd");
String dateString = format.format(date);
System.out.println(dateString);
}