标签:style blog io color ar os java for sp
java.util.Date和String类型的转换是非常常用的,现在总结一下:
1. Date转换为String
//Date --->String DateFormat dft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date dateNow = new Date(System.currentTimeMillis()); String now = dft.format(dateNow); System.out.println(now);
2. String 转换为Date
//String ---->Date
try { DateFormat dft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date startTime = dft.parse("2014-10-15 00:00:00"); System.out.println(startTime.toString()); } catch (ParseException e) { e.printStackTrace(); }
标签:style blog io color ar os java for sp
原文地址:http://www.cnblogs.com/onmyway20xx/p/4076309.html