获取一个月前的当前时间

Date date = new Date();//获取当前时间
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.MONTH, -1);//当前时间前去一个月,即一个月前的时间
SimpleDateFormat dd=new SimpleDateFormat("yyyy-MM-dd");
String d=dd.format(calendar.getTime());
// System.out.println(d);
String dAdd = d.substring(0, 4)+d.substring(5, 7)+d.substring(8, 10);
int timeInt = Integer.parseInt(dAdd);//
// System.out.println(timeInt);//20181101

posted @ 2018-12-04 13:49  雨后丶云初霁  阅读(461)  评论(0编辑  收藏  举报