| | |
| | | return sdf.format(calendar.getTime()); |
| | | } |
| | | |
| | | /** |
| | | * 获取当前年的开始时间 |
| | | * @param time 时间 |
| | | * @return 返回时间 格式yyyy-MM-dd 00:00:00 |
| | | */ |
| | | public static Date getYearStart(Date time) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(time); |
| | | calendar.set(Calendar.MONTH, 1); |
| | | calendar.set(Calendar.DAY_OF_MONTH, 1); |
| | | calendar.set(Calendar.HOUR_OF_DAY, 0); |
| | | calendar.set(Calendar.MINUTE, 0); |
| | | calendar.set(Calendar.SECOND, 0); |
| | | return calendar.getTime(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 日期2000-01-01变2000-01-01 00:00:00 |
| | |
| | | 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 23:59:59 |
| | | */ |
| | | public static Date dayToEndDate(Date date) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(date); |
| | | calendar.set(Calendar.HOUR, 23); |
| | | calendar.set(Calendar.MINUTE, 59); |
| | | calendar.set(Calendar.SECOND, 59); |
| | | return calendar.getTime(); |
| | | } |
| | | |
| | | /**获取月份的天数 |
| | |
| | | calendar.getActualMaximum(Calendar.DAY_OF_MONTH); |
| | | return calendar.getActualMaximum(Calendar.DAY_OF_MONTH); |
| | | } |
| | | |
| | | /**当天多少点前 |
| | | * @param date 时间 |
| | | * @param num 多少点前,不含当点前,24小时制 |
| | | * @return 月份的天数 |
| | | */ |
| | | public static boolean getFrontMinute(Date date,int num) { |
| | | Calendar cal = Calendar.getInstance(); |
| | | cal.setTime(date); |
| | | cal.set(Calendar.HOUR, num-1); |
| | | cal.set(Calendar.MINUTE, 59); |
| | | cal.set(Calendar.SECOND, 59); |
| | | |
| | | return date.compareTo(cal.getTime()) < 1; |
| | | } |
| | | } |