![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 import java.text.SimpleDateFormat; 2 import java.util.Date; 3 import java.text.ParseException; 4 5 public class DateTransform{ 6 7 //JDK中的日期格式(年-月-日) 8 public final static String jdkDateFormat = "yyyy-MM-dd"; 9 10 11 //字符串转换为日期 12 public static Date strToDate(String strDate){ 13 SimpleDateFormat dateFormat = new SimpleDateFormat(jdkDateFormat); 14 Date date = null; 15 try{ 16 date = dateFormat.parse(strDate); 17 }catch(ParseException e){ 18 System.out.println(e.getMessage()); 19 } 20 return date; 21 } 22 23 24 //日期转换为字符串 25 public static String dateToStr(Date date){ 26 SimpleDateFormat dateFormat = new SimpleDateFormat(jdkDateFormat); 27 String strDate = dateFormat.format(date); 28 return strDate; 29 } 30 31 }