Java Code Examples for java.time.LocalTime#parse()

The following examples show how to use java.time.LocalTime#parse() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TemporalAccessorParser.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public TemporalAccessor parse(String text, Locale locale) throws ParseException {
	DateTimeFormatter formatterToUse = DateTimeContextHolder.getFormatter(this.formatter, locale);
	if (LocalDate.class == this.temporalAccessorType) {
		return LocalDate.parse(text, formatterToUse);
	}
	else if (LocalTime.class == this.temporalAccessorType) {
		return LocalTime.parse(text, formatterToUse);
	}
	else if (LocalDateTime.class == this.temporalAccessorType) {
		return LocalDateTime.parse(text, formatterToUse);
	}
	else if (ZonedDateTime.class == this.temporalAccessorType) {
		return ZonedDateTime.parse(text, formatterToUse);
	}
	else if (OffsetDateTime.class == this.temporalAccessorType) {
		return OffsetDateTime.parse(text, formatterToUse);
	}
	else if (OffsetTime.class == this.temporalAccessorType) {
		return OffsetTime.parse(text, formatterToUse);
	}
	else {
		throw new IllegalStateException("Unsupported TemporalAccessor type: " + this.temporalAccessorType);
	}
}
 
Example 2
Source File: LocalTimeAttributeConverter.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public LocalTime convertString(String value) {
    try {
        return LocalTime.parse(value);
    } catch (DateTimeException e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example 3
Source File: DateUtilities.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
public static LocalTime parseTime(String timeAsString, DateTimeFormatter formatter, LocalTime defaultValue) {
	if (StringUtils.isNotBlank(timeAsString)) {
		try {
			return LocalTime.parse(timeAsString, formatter);
		} catch (DateTimeParseException e) {
			logger.debug("Error occurred when parsing time: " + e.getMessage(), e);
		}
	}
	return defaultValue;
}
 
Example 4
Source File: CubaTimeField.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected LocalTime parseValue(String text) {
    if (StringUtils.isNotEmpty(text) && !text.equals(placeholder)) {
        DateTimeFormatter dateTimeFormatter = getDateTimeFormatter();
        return LocalTime.parse(text, dateTimeFormatter);
    } else {
        return null;
    }
}
 
Example 5
Source File: TCKLocalTime.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "sampleToString")
public void factory_parse_validText(int h, int m, int s, int n, String parsable) {
    LocalTime t = LocalTime.parse(parsable);
    assertNotNull(t, parsable);
    assertEquals(t.getHour(), h);
    assertEquals(t.getMinute(), m);
    assertEquals(t.getSecond(), s);
    assertEquals(t.getNano(), n);
}
 
Example 6
Source File: Cursor.java    From vertx-sql-client with Apache License 2.0 5 votes vote down vote up
private LocalTime get_TIME(int column) {
        // Time column is always 8 chars long
        String timeString = dataBuffer_.getCharSequence(columnDataPosition_[column - 1],
            8, charset_[column - 1]).toString();
        return LocalTime.parse(timeString, DRDAConstants.DB2_TIME_FORMAT);
//        return DateTime.timeBytesToTime(dataBuffer_,
//                columnDataPosition_[column - 1],
//                cal,
//                charset_[column - 1]);
    }
 
Example 7
Source File: TCKLocalTime.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "sampleBadParse", expectedExceptions={DateTimeParseException.class})
public void factory_parse_invalidText(String unparsable) {
    LocalTime.parse(unparsable);
}
 
Example 8
Source File: TCKLocalTime.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "sampleBadParse", expectedExceptions={DateTimeParseException.class})
public void factory_parse_invalidText(String unparsable) {
    LocalTime.parse(unparsable);
}
 
Example 9
Source File: TCKLocalTime.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void factory_parse_formatter() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("H m s");
    LocalTime test = LocalTime.parse("14 30 40", f);
    assertEquals(test, LocalTime.of(14, 30, 40));
}
 
Example 10
Source File: TCKLocalTime.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeParseException.class)
public void factory_parse_illegalHour() {
    LocalTime.parse("25:00");
}
 
Example 11
Source File: WhenFindingNextDepatureTimes.java    From chapter-2 with Apache License 2.0 4 votes vote down vote up
private LocalTime at(String time) {
    return LocalTime.parse(time, DateTimeFormatter.ofPattern("H:mm"));
}
 
Example 12
Source File: TCKLocalTime.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = {NullPointerException.class})
public void factory_parse_nullTest() {
    LocalTime.parse((String) null);
}
 
Example 13
Source File: FixedHourSchedule.java    From Wisp with Apache License 2.0 4 votes vote down vote up
/**
 * Parse time in the form of "hh:mm" or "hh:mm:ss"
 */
public FixedHourSchedule(String every, ZoneId zoneId) {
	this(LocalTime.parse(every), zoneId);
}
 
Example 14
Source File: TCKLocalTime.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void factory_parse_formatter_nullFormatter() {
    LocalTime.parse("ANY", null);
}
 
Example 15
Source File: TCKLocalTime.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeParseException.class)
public void factory_parse_illegalHour() {
    LocalTime.parse("25:00");
}
 
Example 16
Source File: PatternScheduleBuilderService.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
private String formatTime(String time, DateTimeFormatter fromFormatToUse, DateTimeFormatter toFormatToUse) {
    LocalTime localTime = LocalTime.parse(time, fromFormatToUse);
    return toFormatToUse.format(localTime);
}
 
Example 17
Source File: UseLocalTime.java    From tutorials with MIT License 4 votes vote down vote up
LocalTime getLocalTimeUsingParseMethod(String timeRepresentation) {
    return LocalTime.parse(timeRepresentation);
}
 
Example 18
Source File: TCKLocalTime.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeParseException.class)
public void factory_parse_illegalSecond() {
    LocalTime.parse("12:12:60");
}
 
Example 19
Source File: LocalTimeStringConverter.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
@Override
public LocalTime fromString(String string) {
    return LocalTime.parse(string);
}
 
Example 20
Source File: ParseStringToTimestamp.java    From levelup-java-examples with Apache License 2.0 3 votes vote down vote up
@Test
public void parse_date_string_in_java8() {

	LocalTime parsedTimeStamp = LocalTime.parse("01:06:45.170");

	assertEquals(1, parsedTimeStamp.getHour());
}