| | |
| | | } |
| | | |
| | | /** |
| | | * @return 获取两个date的时间差,结果为秒 |
| | | * @return 获取两个date的时间差,结果为秒 除 |
| | | */ |
| | | public static long differentSecond(Date startDate, Date endDate) { |
| | | return (endDate.getTime() - startDate.getTime()) / 1000; |
| | | return new BigDecimal(endDate.getTime() - startDate.getTime()).divide(new BigDecimal("1000"), 0, BigDecimal.ROUND_HALF_UP).longValue(); |
| | | // return (endDate.getTime() - startDate.getTime()) / 1000; |
| | | } |
| | | |
| | | /** |
| | |
| | | public static final String STR_DATE_TIME_FULL = "yyyyMMddHHmmssSSS"; |
| | | public static final String STR_HHMMSS = "HH:mm:ss"; |
| | | public static final String STR_HHMM = "HH:mm"; |
| | | public static final String STR_MMDD = "MM-dd"; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * 获取start/end的所有日期字符串 格式MM-dd |
| | | * |
| | | * @param start |
| | | * @param end |
| | | * @return |
| | | */ |
| | | public static List<String> getDatesStringLists(Date start, Date end) { |
| | | List<String> list = new ArrayList<>(); |
| | | int i = getDays(start, end); |
| | | for (int j = 0; j <= i; j++) { |
| | | if (j == 0) { |
| | | list.add(format(start, STR_MMDD)); |
| | | } else { |
| | | list.add(format(plusTime(start, j), STR_MMDD)); |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | public static List<String> getMonthBetween(Date start, Date end) { |
| | | List<String> list = new ArrayList<>(); |
| | | Calendar min = Calendar.getInstance(); |
| | |
| | | return 0; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 日期转换,将接口返回的20180524转为2018-05-24 |
| | | * |
| | | * @param str |
| | | * @return |
| | | */ |
| | | public static String dateConvertion(String str) { |
| | | Date parse = null; |
| | | String dateString = ""; |
| | | try { |
| | | parse = new SimpleDateFormat("yyyyMMdd").parse(str); |
| | | dateString = new SimpleDateFormat("yyyy-MM-dd").format(parse); |
| | | } catch (ParseException e) { |
| | | dateString = null; |
| | | } |
| | | |
| | | return dateString; |
| | | } |
| | | } |