SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日");
Date date = new Date();
System.out.println("当前时间是:" + dateFormat.format(date));
Calendar calendar = Calendar.getInstance();
calendar.setTime(date); // 设置为当前时间
calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1); // 设置为上一个月
date = calendar.getTime();
System.out.println("上一个月的时间: " + dateFormat.format(date));
java 获取 上个月的今天
最新推荐文章于 2025-05-07 09:40:22 发布
本文通过Java代码展示了如何获取并打印当前日期,以及如何利用SimpleDateFormat和Calendar类来获取上一个月的日期。这对于理解Java中日期时间的基本操作非常有帮助。
2199

被折叠的 条评论
为什么被折叠?



