如何利用java得到当前的时间和前一天的时间

2024-12-29 04:55:34
推荐回答(1个)
回答1:

SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
Date beginDate = new Date();
Calendar date = Calendar.getInstance();
date.setTime(beginDate);
date.set(Calendar.DATE, date.get(Calendar.DATE) - 1);
Date endDate = dft.parse(dft.format(date.getTime()));
System.err.println("current:"+beginDate);
System.err.println("yesterday:"+endDate);