就像这种Thu Aug 18 13:20:15 CST 2016转化为yyyyMMdd这样的
本人这样写Date date = sdf1.parse(createtime);这行报错
createtime是Thu Aug 18 13:20:15 CST 2016格式的字符串
本人这样写Date date = sdf1.parse(createtime);这行报错
createtime是Thu Aug 18 13:20:15 CST 2016格式的字符串
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd",Locale.ENGLISH); Date date = sdf1.parse(createtime); String startDate = sdf1.format(date);
这个方法是过时的,转化日期有可能就不对了
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd"); Date date = new Date(createtime); String startDate = sdf1.format(date);
解决方案
40
String dateStr = "Thu Aug 18 13:20:15 CST 2016"; SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); //java.util.Date对象 Date date = sdf.parse(dateStr); String formatStr2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date); System.out.println(formatStr2);