0
点赞
收藏
分享

微信扫一扫

JAVA: 如何显示比当前DATE时间,提前一个月的时间 还有提前20天

评:
Date date = new Date();//当前日期
SimpleDate()Format sdf = new SimpleDateFormat("yyyy/MM/dd");//格式化对象
Calendar calendar = Calendar.getInstance();//日历对象
calendar.setTime(date);//设置当前日期
calendar.add(Calendar.MONTH, -1);//月份减一
System.out.println(sdf.format(calendar.getTime()));//输出格式化的日期


ca.add(Calendar.DAY_OF_MONTH, -20);//提前20天
Calendar.DAY_OF_MONTH 处设定你的特定时间。

举报

相关推荐

0 条评论