/** *@Description:日期转换,将接口返回的20180524转为2018-05-24 *@param str 传递的日期字符串 */ private 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; } /** *@Description:日期转换,将yyyy-MM-dd转为yyyyMMdd *@param str 传递的日期字符串 */ private static String StringToDate(String str) { Date parse = null; String dateString = ""; try { parse=new SimpleDateFormat("yyyy-MM-dd").parse(str); dateString = new SimpleDateFormat("yyyyMMdd").format(parse); } catch (ParseException e) { dateString=null; } return dateString; }
标签:转换,String,dateString,SimpleDateFormat,parse,日期,str,字符串,null From: https://www.cnblogs.com/JYB2021/p/17189448.html