Joda-DateTime Date 与 String 相互转换


【参考文章】: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);
    }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM