java获取前一天日期
import java.util.Calendar; public class Main { public static void main(String[] args) { // 获取今天的日期 Calendar today = Calendar.getInstance(); // 将今天的日期设置为前一天 Calendar yesterday = Calendar.getInstance(); yesterday.set(Calendar.DAY_OF_YEAR, today.get(Calendar.DAY_OF_YEAR) - 1); // 获取前一天的日期 int year = yesterday.get(Calendar.YEAR); int month = yesterday.get(Calendar.MONTH) + 1; int day = yesterday.get(Calendar.DAY_OF_MONTH); String date = year + "-" + month + "-" + day; System.out.println("昨天的日期是:" + date); } }
#################################
标签:java,get,yesterday,日期,Calendar,前一天 From: https://www.cnblogs.com/herd/p/17701305.html