String、Date时间格式互相转换
- String转Date
String startTime = "" //需要转换的是时间
DateFormat format= new SimpleDateFormat("yyyy-MM-dd HH:mm");
Date date = null;
try {
date = format.parse(startTime);
} catch (ParseException e) {
e.printStackTrace();
}
- Date转String
Date startTime = "" //需要转换的是时间
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String time= simpleDateFormat.format(startTime);