DateTimeFormatterFactory.java 文件源码

java
阅读 25 收藏 0 点赞 0 评论 0

项目:lams 作者:
/**
 * Create a new {@code DateTimeFormatter} using this factory.
 * <p>If no specific pattern or style has been defined,
 * the supplied {@code fallbackFormatter} will be used.
 * @param fallbackFormatter the fall-back formatter to use when no specific
 * factory properties have been set (can be {@code null}).
 * @return a new date time formatter
 */
public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter) {
    DateTimeFormatter dateTimeFormatter = null;
    if (StringUtils.hasLength(this.pattern)) {
        dateTimeFormatter = DateTimeFormat.forPattern(this.pattern);
    }
    else if (this.iso != null && this.iso != ISO.NONE) {
        switch (this.iso) {
            case DATE:
                dateTimeFormatter = ISODateTimeFormat.date();
                break;
            case TIME:
                dateTimeFormatter = ISODateTimeFormat.time();
                break;
            case DATE_TIME:
                dateTimeFormatter = ISODateTimeFormat.dateTime();
                break;
            case NONE:
                /* no-op */
                break;
            default:
                throw new IllegalStateException("Unsupported ISO format: " + this.iso);
        }
    }
    else if (StringUtils.hasLength(this.style)) {
        dateTimeFormatter = DateTimeFormat.forStyle(this.style);
    }

    if (dateTimeFormatter != null && this.timeZone != null) {
        dateTimeFormatter = dateTimeFormatter.withZone(DateTimeZone.forTimeZone(this.timeZone));
    }
    return (dateTimeFormatter != null ? dateTimeFormatter : fallbackFormatter);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号