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