java时间提前⼀天,Java在特定⽇期之前提前⼀天
I have a String expired date. But I need to perform some SQL statement the day before expired date falls. I get my expired date and by:
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
String expiredDate = null;
foot
String currentDate = dateFormat.format(new Date());
Calendar cal = Instance();
9394
try {
cal.tTime(dateFormat.par(loanDate));
cal.add(Calendar.WEEK_OF_YEAR, 2);
expiredDate = dateFormat.TimeInMillis());
cal.add(Calendar.WEEK_OF_YEAR, -2);
} catch (ParException e) {
e.printStackTrace();
}
worstThen, I got an if statement to perform SQL statement:
qs2021年世界大学排名
if(expiredDate.equals(currentDate)){
promptExtensionDialog();
}
What I am trying to achieve is for the if statement, instead of the expiredDate itlf, I need to get one day before the expired date and compare with the current date. I wonder how to achieve this?
Thanks in advance.
tiffany thompson
EDIT
try {
丢卒保车
cal.tTime(dateFormat.par(expiredDate));
广州美甲培训cal.add(Calendar.DATE, -1);
expiredDate = dateFormat.TimeInMillis());
} catch (ParException e) {
e.printStackTrace();
}
Toast.makeText(LoanBook.this,
expiredDate, Toast.LENGTH_LONG)
.show();
This returns me the next date instead of previous date. Do you have any ideas?
解决⽅案
Using Java's (pre-8) built-in Date and Time API will eat you alive. U JodaTime for complex DateTime manipulations. Getting the previous day is as simple as this.
DateTime dateTime = new DateTime();
killer是什么意思System.out.println(dateTime);
System.out.println(dateTime.minusDays(1));
If you don't want any external libraries:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String strDate = "2014-10-28";
bread可数吗眼见为实耳听为虚是什么意思Date date = sdf.par(strDate);
Calendar calendar = Instance();
calendar.tTime(date);
calendar.add(Calendar.DATE, -1);
Date yesterday = Time();
System.out.println(yesterday);
System.out.println(date);