當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。