1. Get the date of the previous day of the current date
Simpledateformat SDF = new simpledateformat ("yyyy-mm-dd"); Calendar Cl = calendar. getinstance (); CL. add (calendar. date,-1); // The value of-1 can be changed as needed. The positive value is the previous date, and the negative value is the later date system. out. println (SDF. format (Cl. gettime ()));
2. Obtain the date of the last day of the last two or more months of the current month.
Simpledateformat SDF = new simpledateformat ("yyyy-mm-dd"); Calendar ar calendar = calendar ar. getinstance (); Calendar. add (calendar. month,-1); // The value of-2 can be changed as needed. The positive value is the previous date, and the negative value is the later date calendar ar. set (calendar. day_of_month, 0); system. out. println ("last day of the last two months:" + SDF. format (calendar. gettime ()));
Last day of the last two months: