處理excel 不規則資料格式時間
public SimpleDateFormat getFormat(String date){
if(date == null){
return null;
}
SimpleDateFormat format = null;
if(date.matches("^[0-9]{4}\\.[0-9]{1,2}\\.[0-9]{1,2}$")){
format = new SimpleDateFormat("yyyy.MM.dd");
}else if(date.matches("^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}$")){
format = new SimpleDateFormat("yyyy-MM-dd");
}else if(date.matches("^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}\\s+[0-9]{2}:[0-9]{2}:[0-9]{2}$")){
format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
}else if(date.matches("^[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}$")){
format = new SimpleDateFormat("yyyy/MM/dd"); //2018/6/2
}else if(date.matches("^[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}-[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}$")){
format = new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss"); //2018/06/26-14:00:00
}else if(date.matches("^[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}\\s+[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}$")){
format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); //2018/06/26-14:00:00
}
return format;
}
SimpleDateFormat string = getFormat(arrayList.get(3)); //3會議時間
Date parse = null;
try {
parse = string.parse(arrayList.get(3));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
sd.setMeetingTime(parse); //交底時間