本文共 1251 字,大约阅读时间需要 4 分钟。
??????????
dateToStringdate?????type????????????yyyy-MM-dd???yyyy-MM-dd HH:mm:ss?public static String dateToString(Object date, String type) { if (date != null) { try { SimpleDateFormat sdf = new SimpleDateFormat(type); return sdf.format(date); } catch (Exception e) { e.printStackTrace(); } } return "";} date?String?????????Date????????IllegalArgumentException???SimpleDateFormat???????????????????StringToDatedateStr??????type????????????yyyy-MM-dd???yyyy-MM-dd HH:mm:ss?public static Date StringToDate(String date, String type) { try { SimpleDateFormat sdf = new SimpleDateFormat(type); return sdf.parse(date); } catch (Exception e) { e.printStackTrace(); } return null;} StringToDate?dateToString???????????????public static void main(String[] args) { String type = "yyyy-MM-dd HH:mm:ss"; // ???? long date = 1559014035000L; // ??? Date riqi = StringToDate(date, type); System.out.println(riqi); String shiJian = dateToString(riqi, type); System.out.println(shiJian);} 转载地址:http://lskr.baihongyu.com/