JAva指定年月の先月日付取得
1040 ワード
JAva指定月の前月を取得
String rq = "2017-10";
DateFormat format2 = new SimpleDateFormat("yyyy-MM");
Date date = new Date();
try{
date = format2.parse(rq);
}catch(Exception e){
e.printStackTrace();
}
Calendar c = Calendar.getInstance();
c.setTime(date);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
c.add(Calendar.MONTH, -1);
String time = format.format(c.getTime());
System.out.println(time);