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


Java DateTimeFormatterBuilder.toFormatter方法代码示例

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


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

示例1: TimeConverter

import org.joda.time.format.DateTimeFormatterBuilder; //导入方法依赖的package包/类
/**
 * creates instance with specific rounding.
 *
 * @param rounding
 *            rounding
 */
public TimeConverter(Rounding rounding) {
    this.rounding = rounding;
    char separator = DecimalFormatSymbols.getInstance().getDecimalSeparator();
    DateTimeFormatterBuilder parseBuilder = new DateTimeFormatterBuilder().appendHourOfDay(2).appendLiteral(':')
            .appendMinuteOfHour(2);
    parseBuilder.appendOptional(new DateTimeFormatterBuilder().appendLiteral(separator)
            .appendFractionOfMinute(0, 1).toParser());
    this.parse = parseBuilder.toFormatter();
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder().appendHourOfDay(1).appendLiteral(':')
            .appendMinuteOfHour(2);
    DateTimeFormatterBuilder builderFull = new DateTimeFormatterBuilder().appendHourOfDay(2).appendLiteral(':')
            .appendMinuteOfHour(2);
    if (rounding != Rounding.MINUTE) {
        builder.appendLiteral(separator).appendFractionOfMinute(1, 1);
        builderFull.appendLiteral(separator).appendFractionOfMinute(1, 1);
    }
    this.print = builder.toFormatter();
    this.printFull = builderFull.toFormatter();
    this.duration = new DecimalFormat("###.#");
    this.printXml = ISODateTimeFormat.hourMinuteSecond();
}
 
开发者ID:jub77,项目名称:grafikon,代码行数:28,代码来源:TimeConverter.java

示例2: testMultiParsers

import org.joda.time.format.DateTimeFormatterBuilder; //导入方法依赖的package包/类
public void testMultiParsers() {
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    DateTimeParser[] parsers = new DateTimeParser[3];
    parsers[0] = DateTimeFormat.forPattern("MM/dd/yyyy").withZone(DateTimeZone.UTC).getParser();
    parsers[1] = DateTimeFormat.forPattern("MM-dd-yyyy").withZone(DateTimeZone.UTC).getParser();
    parsers[2] = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss").withZone(DateTimeZone.UTC).getParser();
    builder.append(DateTimeFormat.forPattern("MM/dd/yyyy").withZone(DateTimeZone.UTC).getPrinter(), parsers);

    DateTimeFormatter formatter = builder.toFormatter();

    formatter.parseMillis("2009-11-15 14:12:12");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:SimpleJodaTests.java

示例3: literalDate

import org.joda.time.format.DateTimeFormatterBuilder; //导入方法依赖的package包/类
public static String literalDate(Date date) {
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder()
            .appendDayOfWeekShortText().appendLiteral(" ")
            .appendDayOfMonth(1).appendLiteral(". ")
            .appendMonthOfYearShortText();

    if (date.getYear() != new Date().getYear()) {
        builder.appendLiteral(" ").appendYear(2, 4);
    }

    org.joda.time.format.DateTimeFormatter formatter = builder
            .toFormatter();

    return formatter.print(date.getTime());
}
 
开发者ID:darrillaga,项目名称:togg,代码行数:16,代码来源:DateTimeFormatter.java

示例4: createFormat

import org.joda.time.format.DateTimeFormatterBuilder; //导入方法依赖的package包/类
static
private DateTimeFormatter createFormat(){
	DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder()
		.appendSignedDecimal(HoursOfEpochFieldType.getInstance(), 1, 4)
		.appendLiteral(':')
		.appendFixedDecimal(DateTimeFieldType.minuteOfHour(), 2)
		.appendLiteral(':')
		.appendFixedDecimal(DateTimeFieldType.secondOfMinute(), 2);

	return builder.toFormatter();
}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:12,代码来源:SecondsSinceMidnight.java

示例5: 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

示例6: getFormatter

import org.joda.time.format.DateTimeFormatterBuilder; //导入方法依赖的package包/类
protected DateTimeFormatter getFormatter(int flags) {
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    boolean hasDate = appendDateFormats(builder, flags);
    boolean hasTime = hasTime();
    if (hasTime) {
        if (!hasDate) {
            builder.clear();
        }
        appendTimeFormats(builder, flags);
    }
    return builder.toFormatter();
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:13,代码来源:PartialTime.java

示例7: 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

示例8: forStrptimePattern

import org.joda.time.format.DateTimeFormatterBuilder; //导入方法依赖的package包/类
/**
 * Factory to create a formatter from a strptime pattern string.
 * This models the commonly supported features of strftime from POSIX
 * (where it can).
 * <p>
 * The format may contain locale specific output, and this will change as
 * you change the locale of the formatter.
 * Call DateTimeFormatter.withLocale(Locale) to switch the locale.
 * For example:
 * <pre>
 * DateTimeFormat.forPattern(pattern).withLocale(Locale.FRANCE).print(dt);
 * </pre>
 *
 * @param pattern  pattern specification
 * @return the formatter
 *  @throws IllegalArgumentException if the pattern is invalid
 */
public static DateTimeFormatter forStrptimePattern(String pattern) {
  if (pattern == null || pattern.length() == 0)
    throw new IllegalArgumentException("Empty date time pattern specification");

  DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
  parseToBuilder(builder, pattern);
  DateTimeFormatter formatter = builder.toFormatter();

  return formatter;
}
 
开发者ID:kyoren,项目名称:https-github.com-h2oai-h2o-3,代码行数:28,代码来源:ParseTime.java


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