当前位置: 首页>>代码示例>>Java>>正文


Java DateTimeFormatterBuilder.appendLiteral方法代码示例

本文整理汇总了Java中org.joda.time.format.DateTimeFormatterBuilder.appendLiteral方法的典型用法代码示例。如果您正苦于以下问题:Java DateTimeFormatterBuilder.appendLiteral方法的具体用法?Java DateTimeFormatterBuilder.appendLiteral怎么用?Java DateTimeFormatterBuilder.appendLiteral使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.joda.time.format.DateTimeFormatterBuilder的用法示例。


在下文中一共展示了DateTimeFormatterBuilder.appendLiteral方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getFormatter

import org.joda.time.format.DateTimeFormatterBuilder; //导入方法依赖的package包/类
public DateTimeFormatter getFormatter(int flags) {
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    boolean hasDate = appendDateFormats(builder, flags);
    if (poy != null) {
        if (!JodaTimeUtils.hasField(base, DateTimeFieldType.monthOfYear())) {
            // Assume poy is compatible with whatever was built and
            // poy.toISOString() does the correct thing
            builder.appendLiteral("-");
            builder.appendLiteral(poy.toISOString());
            hasDate = true;
        }
    }
    if (dow != null) {
        if (!JodaTimeUtils.hasField(base, DateTimeFieldType.monthOfYear()) && !JodaTimeUtils.hasField(base, DateTimeFieldType.dayOfWeek())) {
            builder.appendLiteral("-");
            builder.appendLiteral(dow.toISOString());
            hasDate = true;
        }
    }
    if (hasTime()) {
        if (!hasDate) {
            builder.clear();
        }
        appendTimeFormats(builder, flags);
    } else if (tod != null) {
        if (!hasDate) {
            builder.clear();
        }
        // Assume tod is compatible with whatever was built and
        // tod.toISOString() does the correct thing
        builder.appendLiteral("T");
        builder.appendLiteral(tod.toISOString());
    }
    return builder.toFormatter();
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:36,代码来源:CompositePartialTime.java

示例2: appendTimeFormats

import org.joda.time.format.DateTimeFormatterBuilder; //导入方法依赖的package包/类
protected boolean appendTimeFormats(DateTimeFormatterBuilder builder, int flags) {
    boolean alwaysPad = (flags & SUTime.FORMAT_PAD_UNKNOWN) != 0;
    boolean hasTime = hasTime();
    DateTimeFieldType sdft = JodaTimeUtils.getMostSpecific(base);
    if (hasTime) {
        builder.appendLiteral("T");
        if (JodaTimeUtils.hasField(base, DateTimeFieldType.hourOfDay())) {
            builder.appendHourOfDay(2);
        } else if (JodaTimeUtils.hasField(base, DateTimeFieldType.clockhourOfDay())) {
            builder.appendClockhourOfDay(2);
        } else {
            builder.appendLiteral(SUTime.PAD_FIELD_UNKNOWN2);
        }
        if (JodaTimeUtils.hasField(base, DateTimeFieldType.minuteOfHour())) {
            builder.appendLiteral(":");
            builder.appendMinuteOfHour(2);
        } else if (alwaysPad || JodaTimeUtils.isMoreGeneral(DateTimeFieldType.minuteOfHour(), sdft, base.getChronology())) {
            builder.appendLiteral(":");
            builder.appendLiteral(SUTime.PAD_FIELD_UNKNOWN2);
        }
        if (JodaTimeUtils.hasField(base, DateTimeFieldType.secondOfMinute())) {
            builder.appendLiteral(":");
            builder.appendSecondOfMinute(2);
        } else if (alwaysPad || JodaTimeUtils.isMoreGeneral(DateTimeFieldType.secondOfMinute(), sdft, base.getChronology())) {
            builder.appendLiteral(":");
            builder.appendLiteral(SUTime.PAD_FIELD_UNKNOWN2);
        }
        if (JodaTimeUtils.hasField(base, DateTimeFieldType.millisOfSecond())) {
            builder.appendLiteral(".");
            builder.appendMillisOfSecond(3);
        }
        // builder.append(isoTimeFormatter);
    }
    return hasTime;
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:36,代码来源:PartialTime.java

示例3: createDateTimeFormatter

import org.joda.time.format.DateTimeFormatterBuilder; //导入方法依赖的package包/类
public static DateTimeFormatter createDateTimeFormatter(String format)
{
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    for (Token token : tokenize(format)) {
        switch (token.getType()) {
            case DateFormat.TEXT:
                builder.appendLiteral(token.getText());
                break;
            case DateFormat.DD:
                builder.appendDayOfMonth(2);
                break;
            case DateFormat.HH24:
                builder.appendHourOfDay(2);
                break;
            case DateFormat.HH:
                builder.appendHourOfHalfday(2);
                break;
            case DateFormat.MI:
                builder.appendMinuteOfHour(2);
                break;
            case DateFormat.MM:
                builder.appendMonthOfYear(2);
                break;
            case DateFormat.SS:
                builder.appendSecondOfMinute(2);
                break;
            case DateFormat.YY:
                builder.appendTwoDigitYear(2050);
                break;
            case DateFormat.YYYY:
                builder.appendYear(4, 4);
                break;
            case DateFormat.UNRECOGNIZED:
            default:
                throw new PrestoException(
                        StandardErrorCode.INVALID_FUNCTION_ARGUMENT,
                        String.format("Failed to tokenize string [%s] at offset [%d]", token.getText(), token.getCharPositionInLine()));
        }
    }

    try {
        return builder.toFormatter();
    }
    catch (UnsupportedOperationException e) {
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e);
    }
}
 
开发者ID:y-lan,项目名称:presto,代码行数:48,代码来源:DateFormatParser.java


注:本文中的org.joda.time.format.DateTimeFormatterBuilder.appendLiteral方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。