public static final String TIME_FORMAT = "hh:mm"; public static final String DAY_TIME_FORMAT = "yyyy-MM-dd HH:mm"; public static Date string2Date(String dateString, String pattern) { DateFormat df = new SimpleDateFormat(pattern); Date date = null; try { date = df.parse(dateString); } catch (Exception e) { e.printStackTrace(); } return date; } public static String date2String(Date date, String pattern) { DateFormat df = new SimpleDateFormat(pattern); String format = null; try { format = df.format(date); } catch (Exception e) { e.printStackTrace(); } return format; } public static Long string2Long(String date, String pattern) { DateFormat df = new SimpleDateFormat(pattern); Date result = null; try { result = df.parse(date); } catch (ParseException e) { e.printStackTrace(); } if (null == result) { return null; } return result.getTime(); }
Date格式互转
最新推荐文章于 2023-05-28 16:48:24 发布