JAVA提供了方便的时间转换API
获取当前时间返回String类型格式yyyy-MM-dd
Date转字符串
Date date = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = formatter.format(date);
System.out.print(dateString);
字符串转Date
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date date = null;
String str = "2017-02-18";
try {
date = format.parse(str);
System.out.print(date);
} catch (ParseException e) {
e.printStackTrace();
}