java 获取当前时间月加1 ,年加1

Calendar cal = Calendar.getInstance();
int year =cal.get(Calendar.YEAR)+1;
int month=cal.get(Calendar.MONTH)+1;
cal.add(Calendar.MONTH, 1);
//Date date = cal.getTime(); //结果
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
cal.set(Calendar.YEAR,cal.get(Calendar.YEAR)+1);
Date date=cal.getTime();
System.out.println(sdf.format(date));

posted @ 2016-01-21 16:21  阿窟窿  阅读(11774)  评论(0编辑  收藏  举报