生成一个java方法参数1传入String类型的日期参数2格式化成指定的日期格式返回String类型
public static String formatDate(String dateStr, String format) { DateFormat originalFormat = new SimpleDateFormat("yyyy-MM-dd"); // 默认日期格式 Date date; try { date = originalFormat.parse(dateStr); } catch (ParseException e) { e.printStackTrace(); return null; } DateFormat targetFormat = new SimpleDateFormat(format); // 指定日期格式 return targetFormat.format(date); }
原文地址: http://www.cveoy.top/t/topic/eN9t 著作权归作者所有。请勿转载和采集!