Java源码示例:org.joda.time.format.DateTimeParser

示例1
public TikaPoweredMetadataExtracter(String extractorContext, HashSet<String> supportedMimeTypes, HashSet<String> supportedEmbedMimeTypes)
{
    super(supportedMimeTypes, supportedEmbedMimeTypes);

    this.extractorContext = extractorContext;

    // TODO Once TIKA-451 is fixed this list will get nicer
    DateTimeParser[] parsersUTC = {
        DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'").getParser(),
        DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ").getParser()
    };
    DateTimeParser[] parsers = {
        DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss").getParser(),
        DateTimeFormat.forPattern("yyyy-MM-dd").getParser(),
        DateTimeFormat.forPattern("yyyy/MM/dd HH:mm:ss").getParser(),
        DateTimeFormat.forPattern("yyyy/MM/dd").getParser(),
            DateTimeFormat.forPattern("EEE MMM dd hh:mm:ss zzz yyyy").getParser()
    };

    this.tikaUTCDateFormater = new DateTimeFormatterBuilder().append(null, parsersUTC).toFormatter().withZone(DateTimeZone.UTC);
    this.tikaDateFormater = new DateTimeFormatterBuilder().append(null, parsers).toFormatter();
}
 
示例2
private static long parseTodayInstant(String input, final Chronology chrono, long now) {
    final DateTime n = new DateTime(now, chrono);

    for (final DateTimeParser p : today) {
        final DateTimeParserBucket bucket =
            new DateTimeParserBucket(0, chrono, null, null, 2000);

        bucket.saveField(chrono.year(), n.getYear());
        bucket.saveField(chrono.monthOfYear(), n.getMonthOfYear());
        bucket.saveField(chrono.dayOfYear(), n.getDayOfYear());

        try {
            p.parseInto(bucket, input, 0);
        } catch (IllegalArgumentException e) {
            // pass-through
            continue;
        }

        return bucket.computeMillis();
    }

    throw new IllegalArgumentException(input + " is not a valid instant");
}
 
示例3
private static long parseFullInstant(String input, final Chronology chrono) {
    for (final DateTimeParser p : full) {
        final DateTimeParserBucket bucket =
            new DateTimeParserBucket(0, chrono, null, null, 2000);

        try {
            p.parseInto(bucket, input, 0);
        } catch (IllegalArgumentException e) {
            // pass-through
            continue;
        }

        return bucket.computeMillis();
    }

    throw new IllegalArgumentException(input + " is not a valid instant");
}
 
示例4
public static DateTimeFormatter getDateTimeFormatter() {

    if (dateTimeTZFormat == null) {
      DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("yyyy-MM-dd");
      DateTimeParser optionalTime = DateTimeFormat.forPattern(" HH:mm:ss").getParser();
      DateTimeParser optionalSec = DateTimeFormat.forPattern(".SSS").getParser();
      DateTimeParser optionalZone = DateTimeFormat.forPattern(" ZZZ").getParser();

      dateTimeTZFormat = new DateTimeFormatterBuilder().append(dateFormatter).appendOptional(optionalTime)
        .appendOptional(optionalSec).appendOptional(optionalZone).toFormatter();
    }

    return dateTimeTZFormat;
  }
 
示例5
public static DateTimeFormatter getTimeFormatter() {
  if (timeFormat == null) {
    DateTimeFormatter timeFormatter = DateTimeFormat.forPattern("HH:mm:ss");
    DateTimeParser optionalSec = DateTimeFormat.forPattern(".SSS").getParser();
    timeFormat = new DateTimeFormatterBuilder().append(timeFormatter).appendOptional(optionalSec).toFormatter();
  }
  return timeFormat;
}
 
示例6
public static FormatDateTimeFormatter getStrictStandardDateFormatter() {
    // 2014/10/10
    DateTimeFormatter shortFormatter = new DateTimeFormatterBuilder()
            .appendFixedDecimal(DateTimeFieldType.year(), 4)
            .appendLiteral('/')
            .appendFixedDecimal(DateTimeFieldType.monthOfYear(), 2)
            .appendLiteral('/')
            .appendFixedDecimal(DateTimeFieldType.dayOfMonth(), 2)
            .toFormatter()
            .withZoneUTC();

    // 2014/10/10 12:12:12
    DateTimeFormatter longFormatter = new DateTimeFormatterBuilder()
            .appendFixedDecimal(DateTimeFieldType.year(), 4)
            .appendLiteral('/')
            .appendFixedDecimal(DateTimeFieldType.monthOfYear(), 2)
            .appendLiteral('/')
            .appendFixedDecimal(DateTimeFieldType.dayOfMonth(), 2)
            .appendLiteral(' ')
            .appendFixedSignedDecimal(DateTimeFieldType.hourOfDay(), 2)
            .appendLiteral(':')
            .appendFixedSignedDecimal(DateTimeFieldType.minuteOfHour(), 2)
            .appendLiteral(':')
            .appendFixedSignedDecimal(DateTimeFieldType.secondOfMinute(), 2)
            .toFormatter()
            .withZoneUTC();

    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder().append(longFormatter.withZone(DateTimeZone.UTC).getPrinter(), new DateTimeParser[]{longFormatter.getParser(), shortFormatter.getParser(), new EpochTimeParser(true)});

    return new FormatDateTimeFormatter("yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||epoch_millis", builder.toFormatter().withZone(DateTimeZone.UTC), Locale.ROOT);
}
 
示例7
private static DateTimeParser offsetElement() {
	return new DateTimeFormatterBuilder().appendTimeZoneOffset("Z", true, 2, 4).toParser();
}
 
示例8
private static DateTimeParser fractionElement() {
	return new DateTimeFormatterBuilder().appendLiteral('.').appendFractionOfSecond(3, 9).toParser();
}