Date date = new Date();
date.setTime(System.currentTimeMillis());//为date设置为系统当前时间
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_MONTH, +1);//+1表示明天(后一天) -1表示昨天(前一天)
date = calendar.getTime();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
System.out.println(format.format(date));//输出为 2016-07-19,当前日期为 2016-07-18
Java中获取明天或者昨天的日期的方法
最新推荐文章于 2023-04-11 16:57:11 发布