| | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 获取当前月的开始时间 |
| | | * |
| | | * @param num 0拿取当月,正代表后,负代表前,值为几个(月) |
| | | * @return 返回时间 格式yyyy-MM-dd 00:00:00 |
| | | */ |
| | | public static String getMonthStart(Integer num) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.add(Calendar.MONTH, num); |
| | | calendar.set(Calendar.DAY_OF_MONTH, 1); |
| | | calendar.set(Calendar.HOUR_OF_DAY, 0); |
| | | calendar.set(Calendar.MINUTE, 0); |
| | | calendar.set(Calendar.SECOND, 0); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); |
| | | return sdf.format(calendar.getTime()); |
| | | } |
| | | |
| | | /** |
| | | * 获取当前月的结束时间 |
| | | * |
| | | * @param num 0拿取当月,正代表后,负代表前,值为几个(月) |
| | | * @return 返回时间 格式yyyy-MM-dd 23:59:59 |
| | | */ |
| | | public static String getMonthEnd(Integer num) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.add(Calendar.MONTH, num); |
| | | calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH)); |
| | | 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 String dayToStart(Date date) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(date); |
| | | calendar.set(Calendar.HOUR, 0); |
| | | calendar.set(Calendar.MINUTE, 0); |
| | | calendar.set(Calendar.SECOND, 0); |
| | | 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 String dayToEnd(Date date) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(date); |
| | | calendar.set(Calendar.HOUR, 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()); |
| | | } |
| | | |
| | | } |