【参考文章】:Joda-Time 的 DateTimeFormat 问题
public class DateFormatUtils { /** HH 必须大写 */
public static final String FORMAT_FULL_TIME_NO_ZONE = "yyyy-MM-dd HH:mm:ss"; public static Date toFormatDate(String dateTimeStr) {
DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(FORMAT_FULL_TIME_NO_ZONE);
DateTime dateTime = dateTimeFormatter.parseDateTime(dateTimeStr);
return dateTime.toDate();
}
public static String toFormatString(Date date) {
return new DateTime(date).toString(FORMAT_FULL_TIME_NO_ZONE);
} public static String toFormatString(Date date, String pattern) {
return new DateTime(date).toString(pattern);
}
}