参考:https://blog.csdn.net/qinchao_mei/article/details/79710933
获取一天的凌晨0:00和午夜24:00(昨天为例)
//得到一个Calendar实例
Calendar calendar = Calendar.getInstance();
//calendar的日期设为今天
calendar.setTime(new Date());
//设置calendar为昨天
calendar.add(Calendar.DATE, -1);
//calendar.add(Calendar.YEAR, -1);//前一年
//calendar.add(Calendar.MONTH, -1);//前一月
Date yesterday = calendar.getTime();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//前一天的字符串
String pre = simpleDateFormat.format(yesterday);
//前一天凌晨0点的字符串
String startTime = pre.substring(0, 10) + " 00:00:00";
//前一天午夜24点的字符串
String endTime = pre.substring(0, 10) + " 24:00:00";
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
//获取前一天的日期字符串
String preDate = dateFormat.format(yesterday);