From 28cf328a098334b51a3e9d2d56f983fb8c862211 Mon Sep 17 00:00:00 2001 From: yujian <yujian@163.com> Date: 星期六, 23 五月 2020 09:54:38 +0800 Subject: [PATCH] 足迹、收藏订单兼容新需求 --- fanli/src/main/java/com/yeshi/fanli/util/TimeUtil.java | 154 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 152 insertions(+), 2 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/util/TimeUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/TimeUtil.java index f2b66aa..b9f4145 100644 --- a/fanli/src/main/java/com/yeshi/fanli/util/TimeUtil.java +++ b/fanli/src/main/java/com/yeshi/fanli/util/TimeUtil.java @@ -86,11 +86,71 @@ date = sdf.parse(st); return date.getTime(); } catch (Exception e) { - // e.printStackTrace(); + e.printStackTrace(); return 0; } } - + + public static Date parseYYYYMM(String st) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); + try { + return sdf.parse(st); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public static Date parseYYYYMMDD_HHMMSS(String st) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + try { + return sdf.parse(st); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public static Date parseYYYYMMDD(String st) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + try { + return sdf.parse(st); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public static Date parseDotYYYYMMDD(String st) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd"); + try { + return sdf.parse(st); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public static Date parseDotCommon(String st) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss"); + try { + return sdf.parse(st); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public static Date parseDotCommon2(String st) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd HH:mm"); + try { + return sdf.parse(st); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + public static long convertAllTimeToTemp(String st) { Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); @@ -102,7 +162,52 @@ } return 0; } + + public static String formatDate(long time) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd HH:mm"); + String date = sdf.format(new Date(time)); + return date; + } + + public static String formatDate(Date time) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd HH:mm"); + String date = sdf.format(time); + return date; + } + public static String formatDateDot(Date time) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd"); + String date = sdf.format(time); + return date; + } + + public static String formatHHMM_12H(Date time) { + SimpleDateFormat sdf = new SimpleDateFormat("hh:mm"); + String date = sdf.format(time); + return date; + } + + public static String formatYMDHHMM(Date date) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + try { + return sdf.format(date); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + + public static String formatDateAddT(Date date) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); + try { + return sdf.format(date); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + public static long convertToTimeTemp(String st, String format) { Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat(format); @@ -126,6 +231,7 @@ } return 0; } + public static long convertDateToTemp2(String st) { Date date = new Date(); @@ -204,6 +310,18 @@ return format; } + public static String getMonthOnlyMM(Date date) { + SimpleDateFormat sdf = new SimpleDateFormat("MM"); + String format = sdf.format(date); + return format; + } + + public static String getYearOnlyYYYY(Date date) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy"); + String format = sdf.format(date); + return format; + } + public static int getDayOfMonth() { Calendar aCalendar = Calendar.getInstance(Locale.CHINA); int day = aCalendar.getActualMaximum(Calendar.DATE); @@ -220,4 +338,36 @@ String date = sdf.format(new Date(time)); return date; } + + /** + * 鑾峰彇涓や釜鏃堕棿鐨勫ぉ鏁板樊鍊� + * + * @param from + * @param to + * @return + */ + public static int getDayDifferenceCount(Date from, Date to) { + Calendar cal1 = Calendar.getInstance(); + cal1.setTime(from); + Calendar cal2 = Calendar.getInstance(); + cal2.setTime(to); + int day1 = cal1.get(Calendar.DAY_OF_YEAR); + int day2 = cal2.get(Calendar.DAY_OF_YEAR); + int year1 = cal1.get(Calendar.YEAR); + int year2 = cal2.get(Calendar.YEAR); + if (year1 != year2) { // 鍚屼竴骞� + int timeDistance = 0; + for (int i = year1; i < year2; i++) { + if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) { // 闂板勾 + timeDistance += 366; + } else { // 涓嶆槸闂板勾 + timeDistance += 365; + } + } + return timeDistance + (day2 - day1); + } else { // 涓嶅悓骞� + return day2 - day1; + } + + } } -- Gitblit v1.8.0