private static final ThreadLocalsimpleDateFormatThreadLocal = new ThreadLocal () { protected SimpleDateFormat initialValue() { return new SimpleDateFormat("dd/MM/yyyy"); } }; public String formatDate(Date input) { if (input == null) { return null; } return simpleDateFormatThreadLocal.get().format(input); } public Date parseDate(String input) throws ParseException { if (input == null) { return null; } return simpleDateFormatThreadLocal.get().parse(input); }
// 或者用jodd.time中的方法
// 或者用jodd.time中的方法// synchronized dateTimeFormatval sdf1: DateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd")// val sdf1 = new SimpleDateFormat("yyyy-MM-dd")// val sdf2 = new SimpleDateFormat("yyyyMMdd")val dateOfDay: DateTime = sdf1.parseDateTime(jMap("localtime"))// val dateDay = sdf2.format(sdf1.parse(jMap("localtime")))val dateDay = dateOfDay.toDate