1、日期转换成String格式化输出:
1 public String getDate() { 2 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); 3 Date date = new Date(); 4 String day = format.format(date); 5 return day; 6 }
2、String类型转化成日期
1 public void toDate(){ 2 String sDate = "2015-08-21"; 3 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 4 try { 5 Date dDate = sdf.parse(sDate); 6 7 } catch (ParseException e) { 8 9 e.printStackTrace(); 10 } 11 }