Java 类org.joda.time.format.DateTimeParser 实例源码

项目:alfresco-repository    文件:TikaPoweredMetadataExtracter.java   
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();
}
项目:heroic    文件:Tasks.java   
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");
}
项目:heroic    文件:Tasks.java   
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");
}
项目:community-edition-old    文件:TikaPoweredMetadataExtracter.java   
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();
}
项目:elasticsearch_my    文件:Joda.java   
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);
}
项目:elasticsearch_my    文件:SimpleJodaTests.java   
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");
}
项目:QDrill    文件:DateUtility.java   
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;
    }
项目:QDrill    文件:DateUtility.java   
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;
}
项目:scribe    文件:CRMMessageFormatUtils.java   
/**
 * 
 * @param finishDate
 * @return
 * @throws Exception
 */
public static final DateTime validateInputDate(final String date, final String permittedDateFormats) throws Exception {

  logger.debug("----Inside validateInputDate, date: " + date + " & permittedDateFormats: " + permittedDateFormats);

  /* Seperate all the formats */
  final String[] defaultDateFormats = permittedDateFormats.split(",");

  /* Create array for all date parsing formats */
  final DateTimeParser[] dateTimeParser = new DateTimeParser[defaultDateFormats.length];

  /* Parse with individual formats */
  for (int i = 0; i < defaultDateFormats.length; i++) {

    /* If format is valid */
    if (defaultDateFormats[i] != null && !"".equals(defaultDateFormats[i])) {

      /* Create new parser for each format */
      dateTimeParser[i] = DateTimeFormat.forPattern(defaultDateFormats[i].trim()).getParser();
    }
  }

  /* Final date formater builder */
  final DateTimeFormatter dateTimeFormatter = new DateTimeFormatterBuilder().append(null, dateTimeParser).toFormatter();

  /* Parse user supplied date */
  final DateTime updatedDate = dateTimeFormatter.parseDateTime(date);

  logger.debug("----Inside validateInputDate, updated date: " + updatedDate);

  /* Return updated date */
  return updatedDate;
}
项目:drill    文件:DateUtility.java   
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;
    }
项目:drill    文件:DateUtility.java   
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;
}
项目:GisGMP    文件:StringToDateTimeConverter.java   
@PostConstruct
public void init() {
    DateTimeParser[] parsers = new DateTimeParser[patterns.length];
    for (int i = 0; i < patterns.length; i++) {
        parsers[i] = DateTimeFormat.forPattern(patterns[i]).getParser();
    }
    dateTimeFormatter = new DateTimeFormatterBuilder().append(null, parsers).toFormatter();
}
项目:GisGMP    文件:FormatterDateTimeRus.java   
@PostConstruct
public void init() {
    DateTimeParser[] parsers = new DateTimeParser[patterns.length];
    for (int i = 0; i < patterns.length; i++) {
        parsers[i] = DateTimeFormat.forPattern(patterns[i]).getParser();
    }
    dateTimeFormatter = new DateTimeFormatterBuilder().append(null, parsers).toFormatter();
}
项目:GisGMP    文件:FormatterDateTimeLocal.java   
@PostConstruct
public void init() {
    DateTimeParser[] parsers = new DateTimeParser[patterns.length];
    for (int i = 0; i < patterns.length; i++) {
        parsers[i] = DateTimeFormat.forPattern(patterns[i]).getParser();
    }
    dateTimeFormatter = new DateTimeFormatterBuilder().append(null, parsers).toFormatter();
}
项目:robin-java-sdk    文件:JodaDateTimeAdapter.java   
/**
 * Build a JodaDateTimeAdapter
 *
 * @param parser Must be a DateTimeFormatter that is capable of parsing
 * @param printer Must be a DateTimeFormatter that is capable of printing
 */
public JodaDateTimeAdapter(DateTimeParser parser, DateTimePrinter printer) {
    if (null == parser || null == printer) {
        throw new IllegalArgumentException("Parser and printer may not be null");
    }

    this.parser = new DateTimeFormatterBuilder().append(parser).toFormatter();
    this.printer = new DateTimeFormatterBuilder().append(printer).toFormatter();
}
项目:scoutmaster    文件:Contact.java   
public void setBirthDate(final String fieldValue)
{
    final DateTimeParser[] parsers =
    { DateTimeFormat.forPattern("yyyy-MM-dd").getParser(), DateTimeFormat.forPattern("yyyy/MM/dd").getParser() };
    final DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers).toFormatter();

    if (fieldValue != null && fieldValue.length() > 0)
    {
        final DateTime date1 = formatter.parseDateTime(fieldValue);
        setBirthDate(new java.sql.Date(date1.toDate().getTime()));
    }
}
项目:change-data-capture    文件:GGSQLTypeConverter.java   
@Override
public Timestamp getTimestamp(DsColumn col, Calendar cal) throws SQLException{
    // How Oracle handles timestamps seems to be a mystery: http://stackoverflow.com/questions/14700962/default-jdbc-date-format-when-reading-date-as-a-string-from-resultset
    // What I have been able to figure out from GoldenGate doc...
    // 
    /*String val =  getStringInt(col);
    DateTimeFormatter sdf =  ISODateTimeFormat.dateTime();
    //DateTimeFormat.forPattern("YYYY-MM-DD:HH:MI.SS.FFFFFF"); // TimeStamp - for some reason the format is a bit differnt....
    DateTimeParser[] parsers = { 
            DateTimeFormat.forPattern("YYYY-MM-DD:HH:MI.SS.FFFFFF" ).getParser(),// TimeStamp - for some reason the format is a bit differnt....
            DateTimeFormat.forPattern( "yyyy-MM-dd" ).getParser() 
                    };
    DateTimeFormatter formatter = new DateTimeFormatterBuilder().append( null, parsers ).toFormatter();

    return new Timestamp(sdf.parseDateTime(val).toDateTime(DateTimeZone.UTC).getMillis());*/


    /// NVM - just using oracle.sql types to parse everything

    // TODO: How do we know if there is a timezone? Maybe we can get it from getGGDataType/getGGDataSubType
    // Use TIMESTAMPTZ/TIMESTAMPLTZ  for time zones
    // GG specific behavior For TIMESTAMP WITH TIME ZONE, 3 options
    //   1) Default GG Extract aborts 
    //   2) INCLUDEREGIONID is set format is YYYY-MM-DD HH:MI.SS.FFFFFF in UTC
    //   3) INCLUDEREGIONIDWITHOFFSET is set  the format is YYYY-MM-DD HH:MI.SS.FFFFFF TZH:TZM (aka - time zone code is added) 
    String val =  getStringInt(col);
    // One would think that Oracle.sql.TIMESTAMP would be able to parse GG time stamps.... not that case :(
    // We try a bunch of ways to prase until one hopefully works.
    logger.debug("getTimestamp value {}", val);
    try {
        return new TIMESTAMP(val).timestampValue(cal);
    } catch (Exception e){
        logger.debug("getTimestamp try parsers");
        DateTimeParser[] parsers = { 
                DateTimeFormat.forPattern( "yyyy-MM-dd:HH:mm:ss.SSSSSS Z" ).getParser(),
                DateTimeFormat.forPattern("yyyy-MM-dd:HH:mm:ss.SSSSSS" ).getParser(),// TimeStamp - for some reason the format is a bit different from the GG doc and JDBC standard
                DateTimeFormat.forPattern("yyyy-MM-dd:HH:mm:ss" ).getParser()
                        };
        DateTimeFormatter formatter = new DateTimeFormatterBuilder().append( null, parsers ).toFormatter();
        DateTime time = formatter.parseDateTime(val);
        logger.debug("time = {}", time);
        if (time != null){
            return new Timestamp(time.toDateTime(DateTimeZone.forTimeZone(cal.getTimeZone())).getMillis()); 
        }
        else{
            logger.warn("Timestamp value {} couldn't be parsed into a valid TimeStamp", val);
            return null;
        }
    }

}
项目:eHMP    文件:HL7DateTimeFormat.java   
private static DateTimeParser twoDigitNumber(DateTimeFieldType fieldType) {
    return new TwoDigitNumber(fieldType);
}
项目:eHMP    文件:HL7DateTimeFormat.java   
private static DateTimeParser dotMilliseconds() {
    return new DateTimeFormatterBuilder().appendLiteral('.').appendMillisOfSecond(3).toParser();
}
项目:eHMP    文件:HL7DateTimeFormat.java   
private static DateTimeParser twoDigitNumber(DateTimeFieldType fieldType) {
    return new TwoDigitNumber(fieldType);
}
项目:eHMP    文件:HL7DateTimeFormat.java   
private static DateTimeParser dotMilliseconds() {
    return new DateTimeFormatterBuilder().appendLiteral('.').appendMillisOfSecond(3).toParser();
}
项目:eHMP    文件:PointInTimeFormatter.java   
/**
 * Creates a new formatter, however you will normally use the factory
 * or the builder.
 *
 * @param printer the internal printer, null if cannot print
 * @param parser  the internal parser, null if cannot parse
 */
public PointInTimeFormatter(DateTimePrinter printer, DateTimeParser parser) {
    super(printer, parser);
}
项目:eHMP    文件:PointInTimeFormatter.java   
/**
 * Creates a new formatter, however you will normally use the factory
 * or the builder.
 *
 * @param printer the internal printer, null if cannot print
 * @param parser  the internal parser, null if cannot parse
 */
public PointInTimeFormatter(DateTimePrinter printer, DateTimeParser parser) {
    super(printer, parser);
}