
@toc
该方法用于获取昨日零点(即昨天00:00:00) 的时间戳,在日常开发中常用于统计昨日全天数据、日志按天归档或定时任务的时间范围设定。通过调用 getDayBegin() 获取当天零点时间,再向前回退一天,即可精确得到昨日起始时刻,确保时间边界的准确性与一致性。
/**
* author:Yu Yang
* 获取昨天的开始时间
*/
public static Date getYestodayBegin(){
Calendar cal = new GregorianCalendar();
cal.setTime(getDayBegin());
cal.add(Calendar.DAY_OF_MONTH, -1);
return cal.getTime();
}结果展示 System.out.println(getYestodayBegin()); //Wed Jun 22 00:00:00 CST 2022
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。