current position:Home>Java gets the date of the previous day

Java gets the date of the previous day

2022-05-15 05:15:44A grain of rice

				SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
                SimpleDateFormat sdf2= new SimpleDateFormat("yyyy-MM-dd 20:00:00");
                Date day = sdf1.parse(String.valueOf(dayNow.split(" ")[0]));
                long ms = day.getTime() - 1*24*3600*1000L;
                Date prevDay = new Date(ms);
                String dayBefore=sdf2.format(prevDay);
                String dayToday=sdf2.format(new Date(day.getTime()));
                System.out.println(" yesterday 20 spot :"+dayBefore);
                System.out.println(" today 20 spot :"+dayToday);

 Insert picture description here
 Insert picture description here

copyright notice
author[A grain of rice],Please bring the original link to reprint, thank you.

Random recommended