org.joda.time.format.DateTimeFormatter#parseDateTime ( )源码实例Demo

下面列出了org.joda.time.format.DateTimeFormatter#parseDateTime ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: twiliochat-android   文件: DateFormatterTest.java
@Test
public void testGetDateFromISOString() {
    String inputDate = "2015-10-21T07:28:00.000Z";

    DateTimeFormatter isoFormatter = ISODateTimeFormat.dateTime();
    DateTime date = null;

    try {
        date = isoFormatter.parseDateTime(inputDate);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    }

    DateTime outputDate = DateFormatter.getDateFromISOString(inputDate);

    assertEquals(outputDate, date);
}
 
源代码2 项目: scava   文件: BitbucketManager.java
public static java.util.Date convertStringToDate(String isoDate) {

		isoDate = isoDate.replaceAll("\"", "");
		DateTimeFormatter parser = ISODateTimeFormat.dateTimeParser();
		DateTime date = parser.parseDateTime(isoDate);
		return date.toDate();
	}
 
源代码3 项目: scava   文件: GitLabManager.java
public static java.util.Date convertStringToDate(String isoDate) {
	
	isoDate = isoDate.replaceAll("\"", "");
	DateTimeFormatter parser = ISODateTimeFormat.dateTimeParser();
	DateTime date = parser.parseDateTime(isoDate);
	return date.toDate();
}
 
源代码4 项目: MeteoInfo   文件: TypeUtilsBak.java
/**
 * Returns the first DateTimeFormatter to parse the string, which represents a DATE
 * <p>
 * It's intended to be called at the start of a large formatting job so that it picks the write format and is not
 * called again. This is an optimization, because the older version, which will try multiple formatters was too
 * slow for large data sets.
 */
public static DateTimeFormatter getDateFormatter(String dateValue) {

    for (DateTimeFormatter formatter : dateFormatters) {
        try {
            formatter.parseDateTime(dateValue);
            return formatter;
        } catch (DateTimeParseException e) {
            // ignore;
        }
    }
    return DATE_FORMATTER;
}
 
@Test
public void testGetAllVersionsInBetween() throws Exception
{
    DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern( "yyyy-MM-dd HH:mm:ssZ" );
    org.joda.time.DateTime dateTime1 = dateTimeFormatter.parseDateTime( "2016-06-20 10:45:50Z" );
    org.joda.time.DateTime dateTime2 = dateTimeFormatter.parseDateTime( "2016-06-21 10:45:50Z" );
    org.joda.time.DateTime dateTime3 = dateTimeFormatter.parseDateTime( "2016-06-22 10:45:50Z" );

    assertEquals( 0, metadataVersionStore.getAllVersionsInBetween( new Date(), new Date() ).size() );

    MetadataVersion metadataVersion2 = new MetadataVersion( "version2", VersionType.ATOMIC );
    metadataVersion2.setHashCode( "12222" );
    metadataVersion2.setCreated( dateTime1.toDate() );
    metadataVersionStore.save( metadataVersion2 );

    MetadataVersion metadataVersion3 = new MetadataVersion( "version3", VersionType.ATOMIC );
    metadataVersion3.setHashCode( "12255" );
    metadataVersion3.setCreated( dateTime2.toDate() );
    metadataVersionStore.save( metadataVersion3 );

    MetadataVersion metadataVersion4 = new MetadataVersion( "version4", VersionType.ATOMIC );
    metadataVersion4.setHashCode( "12267" );
    metadataVersion4.setCreated( dateTime3.toDate() );
    metadataVersionStore.save( metadataVersion4 );

    List<MetadataVersion> allVersionsInBetween = metadataVersionStore.getAllVersionsInBetween( dateTime1.toDate(), dateTime2.toDate() );

    assertEquals( 2, allVersionsInBetween.size() );
    assertEquals( metadataVersion2, allVersionsInBetween.get( 0 ) );
    assertEquals( metadataVersion3, allVersionsInBetween.get( 1 ) );
    assertEquals( 0, metadataVersionStore.getAllVersionsInBetween( new Date(), new Date() ).size() );

    metadataVersionStore.delete( metadataVersion2 );
    metadataVersionStore.delete( metadataVersion3 );
    metadataVersionStore.delete( metadataVersion4 );
}
 
源代码6 项目: MeteoInfo   文件: TypeUtilsBak.java
/**
 * Returns the first DateTimeFormatter to parse the string, which represents a TIME
 * <p>
 * It's intended to be called at the start of a large formatting job so that it picks the write format and is not
 * called again. This is an optimization, because the older version, which will try multiple formatters was too
 * slow for large data sets.
 */
public static DateTimeFormatter getTimeFormatter(String timeValue) {
    for (DateTimeFormatter formatter : timeFormatters) {
        try {
            formatter.parseDateTime(timeValue);
            return formatter;
        } catch (DateTimeParseException e) {
            // ignore;
        }
    }
    return DATE_FORMATTER;
}
 
源代码7 项目: ipst   文件: DateTimeParameter.java
public DateTimeParameter(String dateTime) throws Exception {
    Objects.requireNonNull(dateTime);
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    try {
        this.dateTime = fmt.parseDateTime(dateTime);
    } catch (IllegalArgumentException ex) {
        throw new WebApplicationException(Response.status(Status.BAD_REQUEST)
                .entity("Wrong date parameter format: " + ex.getMessage()).build());
    }
}
 
源代码8 项目: streams   文件: StreamsDateTimeDeserializer.java
/**
 * Applies each additional format in turn, until it can provide a non-null DateTime
 */
@Override
public DateTime deserialize(JsonParser jpar, DeserializationContext context) throws IOException {

  DateTime result = RFC3339Utils.parseToUTC(jpar.getValueAsString());
  Iterator<DateTimeFormatter> iterator = formatters.iterator();
  while ( result == null && iterator.hasNext()) {
    DateTimeFormatter formatter = iterator.next();
    result = formatter.parseDateTime(jpar.getValueAsString());
  }
  return result;
}
 
源代码9 项目: phoenix   文件: RuleGeneratorTest.java
/**
 * Asserts that the value field is between the min/max value fields
 *
 * @param value
 */
private void assertDateBetween(DataValue value) {
    DateTimeFormatter fmtr = DateTimeFormat.forPattern(PherfConstants.DEFAULT_DATE_PATTERN).withZone(DateTimeZone.UTC);

    DateTime dt = fmtr.parseDateTime(value.getValue());
    DateTime min = fmtr.parseDateTime(value.getMinValue());
    DateTime max = fmtr.parseDateTime(value.getMaxValue());

    assertTrue("Value " + dt + " is not after minValue", dt.isAfter(min));
    assertTrue("Value " + dt + " is not before maxValue", dt.isBefore(max));
}
 
源代码10 项目: scava   文件: BitbucketIssue.java
public static Date convertStringToDate(String isoDate) {

		isoDate = isoDate.replaceAll("\"", "");
		DateTimeFormatter parser = ISODateTimeFormat.dateTimeParser();
		DateTime date = parser.parseDateTime(isoDate);
		return date.toDate();
	}
 
源代码11 项目: anno4j   文件: TimeUtils.java
private static boolean testNoMillisFormat(String time) {
    DateTimeFormatter formatNoMillis = ISODateTimeFormat.dateTimeNoMillis().withZoneUTC();

    try {
        formatNoMillis.parseDateTime(time);
        return true;
    }  catch (IllegalArgumentException e) {
        return false;
    }
}
 
源代码12 项目: devicehive-java   文件: DateTimeTypeAdapter.java
@Override
public DateTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {

    if (json.getAsString() == null || json.getAsString().isEmpty()) {
        return null;
    }

    final DateTimeFormatter formatter = DateTimeFormat.forPattern(iso_pattern).withZoneUTC();
    return formatter.parseDateTime(json.getAsString());
}
 
源代码13 项目: ETSMobile-Android2   文件: HoraireComparator.java
@Override
public int compare(IHoraireRows lhs, IHoraireRows rhs) {
    DateTimeFormatter formatter = null;
    DateTime eventDay1 = null;
    DateTime eventDay2 = null;

    if(lhs.getClass().equals(Event.class)){
        formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");
        eventDay1 = formatter.parseDateTime(lhs.getDateDebut());
    }
    if(rhs.getClass().equals(Event.class)){
        formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");
        eventDay2 = formatter.parseDateTime(rhs.getDateDebut());
    }

    if (lhs.getClass().equals(Seances.class)){
        formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss");
        eventDay1 = formatter.parseDateTime(lhs.getDateDebut());
    }
    if (rhs.getClass().equals(Seances.class)){
        formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss");
        eventDay2 = formatter.parseDateTime(rhs.getDateDebut());
    }

    if (eventDay1.isAfter(eventDay2)) {
        return 1;
    }
    else if(eventDay1.isBefore(eventDay2)){
        return -1;
    }
    else if(eventDay1.isEqual(eventDay2)){
        return 0;
    }
    return 0;
}
 
源代码14 项目: anno4j   文件: TimeUtils.java
private static boolean testMillisFormat(String time) {
    DateTimeFormatter formatWithMillis = ISODateTimeFormat.dateTime().withZoneUTC();

    try {
        formatWithMillis.parseDateTime(time);
        return true;
    }  catch (IllegalArgumentException e) {
        return false;
    }
}
 
源代码15 项目: phoenix   文件: RulesApplier.java
public String checkDatePattern(String date) {
    DateTimeFormatter fmtr = DateTimeFormat.forPattern(PherfConstants.DEFAULT_DATE_PATTERN).withZone(DateTimeZone.UTC);;
    DateTime parsedDate = fmtr.parseDateTime(date);
    return fmtr.print(parsedDate);
}
 
@Test
public void testGetNewEntriesForDetectionSchedulerDaily() throws Exception {

  DatasetConfigDTO datasetConfig = new DatasetConfigDTO();
  datasetConfig.setTimeColumn("Date");
  datasetConfig.setTimeUnit(TimeUnit.DAYS);
  datasetConfig.setTimeDuration(1);
  DateTimeZone dateTimeZone = DateTimeZone.UTC;

  AnomalyFunctionDTO anomalyFunction = new AnomalyFunctionDTO();

  DateTimeFormatter dateTimeFormatter = DetectionJobSchedulerUtils.
      getDateTimeFormatterForDataset(datasetConfig, dateTimeZone);
  String currentDateTimeString = "201702140337";
  String currentDateTimeStringRounded = "20170214";
  DateTime currentDateTime = minuteDateTimeFormatter.parseDateTime(currentDateTimeString);
  DateTime currentDateTimeRounded = dateTimeFormatter.parseDateTime(currentDateTimeStringRounded);
  DetectionStatusDTO lastEntryForFunction = null;

  // null last entry
  Map<String, Long> newEntries = DetectionJobSchedulerUtils.
      getNewEntries(currentDateTime, lastEntryForFunction, anomalyFunction, datasetConfig, dateTimeZone);
  Assert.assertEquals(newEntries.size(), 1);
  Assert.assertEquals(newEntries.get(currentDateTimeStringRounded), new Long(currentDateTimeRounded.getMillis()));

  // last entry same as current time
  lastEntryForFunction = new DetectionStatusDTO();
  lastEntryForFunction.setDateToCheckInSDF(currentDateTimeStringRounded);
  lastEntryForFunction.setDateToCheckInMS(currentDateTimeRounded.getMillis());

  newEntries = DetectionJobSchedulerUtils.
      getNewEntries(currentDateTime, lastEntryForFunction, anomalyFunction, datasetConfig, dateTimeZone);
  Assert.assertEquals(newEntries.size(), 0);

  // last entry 1 day before current time
  String lastEntryDateTimeString = "20170213";
  DateTime lastEntryDateTime = dateTimeFormatter.parseDateTime(lastEntryDateTimeString);
  lastEntryForFunction = new DetectionStatusDTO();
  lastEntryForFunction.setDateToCheckInSDF(lastEntryDateTimeString);
  lastEntryForFunction.setDateToCheckInMS(lastEntryDateTime.getMillis());

  newEntries = DetectionJobSchedulerUtils.
      getNewEntries(currentDateTime, lastEntryForFunction, anomalyFunction, datasetConfig, dateTimeZone);
  Assert.assertEquals(newEntries.size(), 1);
  Assert.assertEquals(newEntries.get(currentDateTimeStringRounded), new Long(currentDateTimeRounded.getMillis()));

  // last entry 3 days before current time
  lastEntryDateTimeString = "20170211";
  lastEntryDateTime = dateTimeFormatter.parseDateTime(lastEntryDateTimeString);
  lastEntryForFunction = new DetectionStatusDTO();
  lastEntryForFunction.setDateToCheckInSDF(lastEntryDateTimeString);
  lastEntryForFunction.setDateToCheckInMS(lastEntryDateTime.getMillis());

  newEntries = DetectionJobSchedulerUtils.
      getNewEntries(currentDateTime, lastEntryForFunction, anomalyFunction, datasetConfig, dateTimeZone);
  Assert.assertEquals(newEntries.size(), 3);
  Assert.assertNotNull(newEntries.get("20170212"));
  Assert.assertNotNull(newEntries.get("20170213"));
  Assert.assertNotNull(newEntries.get("20170214"));
  Assert.assertEquals(newEntries.get(currentDateTimeStringRounded), new Long(currentDateTimeRounded.getMillis()));
}
 
源代码17 项目: DrivingAgency   文件: DateTimeUtil.java
public static Date strToDate(String dateTimeStr, String formatStr){
    DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(formatStr);
    DateTime dateTime = dateTimeFormatter.parseDateTime(dateTimeStr);
    return dateTime.toDate();
}
 
源代码18 项目: DrivingAgency   文件: DateTimeUtil.java
public static Date strToDate(String dateTimeStr){
    DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(STANDARD_FORMAT);
    DateTime dateTime = dateTimeFormatter.parseDateTime(dateTimeStr);
    return dateTime.toDate();
}
 
源代码19 项目: ade   文件: LinuxSyslog3164ParserBase.java
/**
 * Retrieves the date parsed from the header of a log. Unless otherwise defined in the properties file,
 * we have to use some logic to figure out the year. After parsing the date, we need to correct the time-zone. 
 * Then we set the dateTime to the current year. Now we need to check the dateTime and see if it's after today.
 * The logic is as follows:
 *      - If Log time-stamp < End of day of today 
 *          (comparing Month, Day, Hour, Minutes, Seconds, with year missing), 
 *          assume it's this year.
 *      - If Log time-stamp > End of day of today 
 *          (comparing Month, Day, Hour, Minutes, Seconds, with year missing), 
 *          assume it's previous year.
 * 
 * The following restrictions will be made to customer for BulkLoad:
 *      - Cannot upload logs older than 11 months.
 *      - Cannot upload logs that are continuous for more than 11 months.
 * 
 * Note: END OF TODAY is purposely chosen instead of START OF TODAY in case a user bulk loads logs that 
 * belongs to today.  It's not possible/likely that a user would bulk load logs from last year of the 
 * same day with the restriction we specified above.
 * @param source the source name string value.
 * @param s the date and time string value.
 * @return Date object with date/time-stamp of the Linux log.
 */
@Override
public final Date toDate(String source, String s) {
    DateTime dt = null;
    for (DateTimeFormatter fmt : dt_formatters) {
        try {
            dt = fmt.parseDateTime(s);
            dt = dt.withZoneRetainFields(INPUT_TIME_ZONE);
            dt = dt.withZone(OUTPUT_TIME_ZONE);

            /* Year must be set after all the time is normalized to the timezone */
            dt = dt.withYear(curYear);

            if (s_linuxAdeExtProperties.isYearDefined()) {
                yearSetter = LinuxSyslogYearSetter.getYearSetter(source);

                /* If years is defined, then, use the defined year as a starting year */
                final int yearToUse = yearSetter.getDesiredYear(dt);
                dt = dt.withYear(yearToUse);
            } else if (dt.isAfter(END_OF_TODAY)) {
                /* Set DateTime to previous year */
                dt = dt.withYear(curYear - 1);
            } else {
                dt = dt.withYear(curYear);
            }

            /* AdeCore will take the Java Date object, and convert 
             * it to the output time-zone, then extract the hour. */
            return dt.toDate();
        } catch (IllegalArgumentException e) {
            /* This exception can occur normally when iterating
             * through the DateTimeFormatter objects. It is only 
             * an error worth noting when the dt object is not null.
             */
            if (dt != null) {
                s_logger.error("Invalid argument encountered.", e);
            }
        }
    }
    throw new IllegalArgumentException("Failed to parse date " + s);
}
 
源代码20 项目: mmall-kay-Java   文件: DateTimeUtil.java
public static Date strToDate(String dateStr, String formatStr) {
    DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(formatStr);
    DateTime dateTime = dateTimeFormatter.parseDateTime(dateStr);
    return dateTime.toDate();
}