public static void main(String[] args){
try {
//获取当前日期
Date date = new Date();
SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
String nowDate = sf.format(date);
System.out.println(nowDate);
//通过日历获取下一天日期
Calendar cal = Calendar.getInstance();
cal.setTime(sf.parse(nowDate));
cal.add(Calendar.DAY_OF_YEAR, +1);
String nextDate_1 = sf.format(cal.getTime());
System.out.println(nextDate_1);
//通过秒获取下一天日期
long time = (date.getTime() / 1000) + 60 * 60 * 24;//秒
date.setTime(time * 1000);//毫秒
String nextDate_2 = sf.format(date).toString();
System.out.println(nextDate_2);
} catch (Exception e) {
// TODO: handle exception
}
}
java获取明天的日期
最新推荐文章于 2024-08-05 04:56:22 发布