我希望昨天的日期或日期不是今天而是过去。我正在使用此代码 -
Calendar calendarMessage = Calendar.getInstance();
Calendar calendarToday = Calendar.getInstance();
calendarMessage.setTime(date);
return calendarMessage.get(Calendar.YEAR) == calendarToday.get(Calendar.YEAR) &&
calendarMessage.get(Calendar.DAY_OF_YEAR) == calendarToday.get(Calendar.DAY_OF_YEAR);
你能帮帮我吗?
答案 0 :(得分:3)
尝试这种方式..
public static String getYesterdayDate() {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -1);
return dateFormat.format(cal.getTime());
}