In Java, get yesterday's current date, you can use the calendar to do it, or you can do it by using date, as follows:
1. Use Calendar to do:
Calendar cal=calendar.getinstance ();
System.out.println (calendar.date);//5
Cal.add (calendar.date,-1);
Date Time=cal.gettime ();
System.out.println (New SimpleDateFormat ("Yyyy-mm-dd hh:mm:ss"). Format (time);
2. Use Date to do:
Date today = new Date ();
/* SYSTEM.OUT.PRINTLN (New SimpleDateFormat ("Yyyy-mm-dd hh:mm:ss"). Format (today);
System.out.println (Today.gettime ());
System.out.println (1477058241633l-86400000l); * *
Date yesterday = new Date (Today.gettime ()-86400000L);//86400000l, which means 1 days = 24 hours x 60 Minutes x 60 seconds x 1000 milliseconds unit is L.
That 86400000L can be written as 24*60*60*1000l
System.out.println (24*60*60*1000l);
System.out.println (New SimpleDateFormat ("Yyyy-mm-dd hh:mm:ss"). Format (yesterday));
Also available in the database, get current time now or sysdate, get yesterday's current time date:
Select DATEADD (Day, 1, now);--In SQL Server
Select Date_sub (current_date (), Interval 1 day)--in MySQL
Select Sysdate-interval ' 1 ' Day from dual;--in Oracle
How to get yesterday's current date in Java