'20191010' 轉換成 2019-10-10 10:10:10
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
以下這個是轉2019-10-10
public static String stringToDate(String date)
{
//把字符串轉成日期
Date dateValue = null;
try {
dateValue = new SimpleDateFormat("yyyyMMdd").parse(date);
} catch (ParseException e) {
e.printStackTrace();
}
//把日期轉成需要的格式
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString = formatter.format(dateValue);
return dateString;
}