| | |
| | | public static Date getYearStart(Date time) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(time); |
| | | calendar.set(Calendar.MONTH, 1); |
| | | calendar.set(Calendar.MONTH, 0); |
| | | calendar.set(Calendar.DAY_OF_MONTH, 1); |
| | | calendar.set(Calendar.HOUR_OF_DAY, 0); |
| | | calendar.set(Calendar.MINUTE, 0); |
| | |
| | | public static Date getYearEnd(Date time) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(time); |
| | | calendar.set(Calendar.MONTH, 12); |
| | | calendar.set(Calendar.MONTH, 11); |
| | | calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DATE)); |
| | | calendar.set(Calendar.HOUR_OF_DAY, 23); |
| | | calendar.set(Calendar.MINUTE, 59); |
| | |
| | | calendar.set(Calendar.SECOND, 59); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); |
| | | return sdf.format(calendar.getTime()); |
| | | } |
| | | |
| | | /**这天的开始时间 |
| | | * 日期2000-01-01变2000-01-01 00:00:00 |
| | | */ |
| | | public static Date dayToStartDate(Date date) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(date); |
| | | calendar.set(Calendar.HOUR_OF_DAY, 0); |
| | | calendar.set(Calendar.MINUTE, 0); |
| | | calendar.set(Calendar.SECOND, 0); |
| | | return calendar.getTime(); |
| | | } |
| | | |
| | | /**这天的最后时间 |
| | |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); |
| | | return sdf.format(calendar.getTime()); |
| | | } |
| | | |
| | | /** |
| | | * 获取时间当月剩余天数 |
| | | * */ |
| | | public static Integer getMonthSurplus(Date date) { |
| | | Calendar month = Calendar.getInstance(); |
| | | month.setTime(new Date()); |
| | | month.set(Calendar.DATE, 1); |
| | | month.roll(Calendar.DATE, -1); |
| | | return month.getActualMaximum(Calendar.DATE) - Calendar.getInstance().get(Calendar.DAY_OF_MONTH); |
| | | } |
| | | |
| | | /**获取当前时间所在周的周一00:00:00*/ |
| | | public static Date getMonday(Date date) { |
| | | Calendar calendar = Calendar.getInstance(Locale.CHINA); |
| | | calendar.setTime(date); |
| | | //以周一为首日 |
| | | calendar.setFirstDayOfWeek(Calendar.MONDAY); |
| | | calendar.set(Calendar.HOUR_OF_DAY, 0); |
| | | calendar.set(Calendar.MINUTE, 0); |
| | | calendar.set(Calendar.SECOND, 0); |
| | | //周一 |
| | | calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); |
| | | return calendar.getTime(); |
| | | } |
| | | } |