java
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class TimeDemo {
public static void main(String[] args) {
Calendar calendarDay = Calendar.getInstance();
calendarDay.add(Calendar.DATE, -1);
//查询今日时间
String startTime = new SimpleDateFormat("yyyy-MM-dd 00:00:00").format(new Date());
String endTime = new SimpleDateFormat("yyyy-MM-dd 23:59:59").format(new Date());
//查询昨日时间
String startTime1 = new SimpleDateFormat("yyyy-MM-dd 00:00:00").format(calendarDay.getTime());
String endTime1 = new SimpleDateFormat("yyyy-MM-dd 23:59:59").format(calendarDay.getTime());
/*今日2024-01-05 00:00:00结束2024-01-05 23:59:59*/
System.out.println("今日"+startTime+"结束"+endTime);
/*昨日2024-01-04 00:00:00结束2024-01-04 23:59:59*/
System.out.println("昨日"+startTime1+"结束"+endTime1);
}
}