在程序里面要获取当前的开始时间和结束时间,在网上看到了这篇文章,被我收了~~~
当天开始时间
- Calendar currentDate = new GregorianCalendar();
- currentDate.set(Calendar.HOUR_OF_DAY, 0);
- currentDate.set(Calendar.MINUTE, 0);
- currentDate.set(Calendar.SECOND, 0);
- dateCursor.setTodayStart((Date)currentDate.getTime().clone());
当天结束时间:
- Calendar currentDate = new GregorianCalendar();
- currentDate.set(Calendar.HOUR_OF_DAY, 23);
- currentDate.set(Calendar.MINUTE, 59);
- currentDate.set(Calendar.SECOND, 59);
- dateCursor.setTodayEnd((Date)currentDate.getTime().clone());
当周开始时间:
- Calendar currentDate = new GregorianCalendar();
- currentDate.setFirstDayOfWeek(Calendar.MONDAY);
- currentDate.set(Calendar.HOUR_OF_DAY, 0);
- currentDate.set(Calendar.MINUTE, 0);
- currentDate.set(Calendar.SECOND, 0);
- currentDate.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
- dateCursor.setWeekStart((Date)currentDate.getTime().clone());
当周结束时间:
- Calendar currentDate = new GregorianCalendar();
- currentDate.setFirstDayOfWeek(Calendar.MONDAY);
- currentDate.set(Calendar.HOUR_OF_DAY, 23);
- currentDate.set(Calendar.MINUTE, 59);
- currentDate.set(Calendar.SECOND, 59);
- currentDate.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
- dateCursor.setWeekEnd((Date)currentDate.getTime().clone());