/**
* 获取今天开始时间
*/
public static Date getStartTime() {
Calendar todayStart = Calendar.getInstance();
todayStart.set(Calendar.HOUR, 0); //小时
todayStart.set(Calendar.MINUTE, 0); //分钟
todayStart.set(Calendar.SECOND, 0); //秒
todayStart.set(Calendar.MILLISECOND, 0); //毫秒
return todayStart.getTime();
}
/**
* 获取今天结束时间
*/
public static Date getEndTime() {
Calendar todayEnd = Calendar.getInstance();
todayEnd.set(Calendar.HOUR, 23);
todayEnd.set(Calendar.MINUTE, 59);
todayEnd.set(Calendar.SECOND, 59);
todayEnd.set(Calendar.MILLISECOND, 999);
return todayEnd.getTime();
}
/**
* 获取今天开始时间 时间戳形式
*/
public static long getStartTimeMil() {
Calendar todayStart = Calendar.getInstance();
todayStart.set(Calendar.HOUR, 0); //小时
todayStart.set(Calendar.MINUTE, 0); //分钟
todayStart.set(Calendar.SECOND, 0); //秒
todayStart.set(Calendar.MILLISECOND, 0); //毫秒
return todayStart.getTimeInMillis();
}
/**
* 获取今天结束时间 时间戳形式
*/
public static long getEndTimeMil() {
Calendar todayEnd = Calendar.getInstance();
todayEnd.set(Calendar.HOUR, 23);
todayEnd.set(Calendar.MINUTE, 59);
todayEnd.set(Calendar.SECOND, 59);
todayEnd.set(Calendar.MILLISECOND, 999);
return todayEnd.getTimeInMillis();
}
日期时间获取当天0点时间 字符串形式
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 00:00:00", Locale.CHINA);
String beginTime = formatter.format(new Date()) ;