SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,S");
Calendar todayStart = Calendar.getInstance();
todayStart.set(Calendar.HOUR, 0);
todayStart.set(Calendar.MINUTE, 0);
todayStart.set(Calendar.SECOND, 0);
todayStart.set(Calendar.MILLISECOND, 0);
System.out.println(sf.format(todayStart.getTime()));
Calendar todayEnd = Calendar.getInstance();
todayEnd.set(Calendar.HOUR, 23);
todayEnd.set(Calendar.MINUTE, 59);
todayEnd.set(Calendar.SECOND, 59);
todayEnd.set(Calendar.MILLISECOND, 999);
System.out.println(sf.format(todayEnd.getTime()));
/* output
2010-04-30 00:00:00,0
2010-04-30 23:59:59,999
*/
获取今天的开始时间和结束时间
最新推荐文章于 2021-03-24 17:16:41 发布