本文整理匯總了Java中java.time.LocalTime.parse方法的典型用法代碼示例。如果您正苦於以下問題:Java LocalTime.parse方法的具體用法?Java LocalTime.parse怎麽用?Java LocalTime.parse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.time.LocalTime
的用法示例。
在下文中一共展示了LocalTime.parse方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testTimePointFilter_1215_10
import java.time.LocalTime; //導入方法依賴的package包/類
@Test
public void testTimePointFilter_1215_10() throws ParseException {
TimePointFilter instance = new TimePointFilter(LocalTime.parse("12:15"),10);
FilterResult result = instance.filter(data);
List<VaultEntry> filteredData = new ArrayList<>();
filteredData.add(new VaultEntry(VaultEntryType.STRESS, TestFunctions.creatNewDateToCheckFor("2017.06.29-12:11"), 17.25));
filteredData.add(new VaultEntry(VaultEntryType.HEART_RATE_VARIABILITY, TestFunctions.creatNewDateToCheckFor("2017.06.29-12:11"), 41.0, 131.0));
filteredData.add(new VaultEntry(VaultEntryType.HEART_RATE, TestFunctions.creatNewDateToCheckFor("2017.06.29-12:21"), 51.0));
filteredData.add(new VaultEntry(VaultEntryType.HEART_RATE_VARIABILITY, TestFunctions.creatNewDateToCheckFor("2017.06.29-12:21"), 44.0, 127.0));
filteredData.add(new VaultEntry(VaultEntryType.STRESS, TestFunctions.creatNewDateToCheckFor("2017.06.29-12:21"), 18.25));
List<Pair<Date, Date>> timeSeries = new ArrayList<>();
timeSeries.add(new Pair<>(TestFunctions.creatNewDateToCheckFor("2017.06.29-12:11"), TestFunctions.creatNewDateToCheckFor("2017.06.29-12:21")));
FilterResult checkForThisResult = new FilterResult(filteredData, timeSeries);
assertEquals(result.filteredData, checkForThisResult.filteredData);
assertEquals(result.timeSeries, checkForThisResult.timeSeries);
//assertEquals(result, checkForThisResult);
}
示例2: main
import java.time.LocalTime; //導入方法依賴的package包/類
public static void main(String[] args) {
// Hours, minutes
LocalTime timeHrsMin = LocalTime.of(12, 12);
// Hours, minutes and seconds
LocalTime timeHrsMinSec = LocalTime.of(0, 12, 6);
// Hours, minutes, seconds and nanoseconds
LocalTime timeHrsMinSecNano = LocalTime.of(14, 7, 10, 998654578);
// DateTimeException
//LocalTime timeHrsMin1 = LocalTime.of(120, 12);// Runtime exception
//LocalTime timeHrsMin2 = LocalTime.of(9986545781, 12);// Compilation error
// To get the current time from the system clock, use the static method now()
LocalTime date3 = LocalTime.now();
// Parse a string to instantiate LocalTime by using its static method parse()
LocalTime time = LocalTime.parse("15:08:23");
}
示例3: testDateTimePointFilter_0640_30
import java.time.LocalTime; //導入方法依賴的package包/類
@Test
public void testDateTimePointFilter_0640_30() throws ParseException {
TimePointFilter instance = new TimePointFilter(LocalTime.parse("06:40"),30);
FilterResult result = instance.filter(data);
List<VaultEntry> filteredData = new ArrayList<>();
filteredData.add(new VaultEntry(VaultEntryType.SLEEP_LIGHT, TestFunctions.creatNewDateToCheckFor("2017.06.29-06:13"), 9.0));
filteredData.add(new VaultEntry(VaultEntryType.HEART_RATE, TestFunctions.creatNewDateToCheckFor("2017.06.29-06:16"), 66.0));
filteredData.add(new VaultEntry(VaultEntryType.HEART_RATE_VARIABILITY, TestFunctions.creatNewDateToCheckFor("2017.06.29-06:16"), 50.0, 93.0));
filteredData.add(new VaultEntry(VaultEntryType.STRESS, TestFunctions.creatNewDateToCheckFor("2017.06.29-06:16"), 30.25));
filteredData.add(new VaultEntry(VaultEntryType.SLEEP_LIGHT, TestFunctions.creatNewDateToCheckFor("2017.06.29-06:22"), 7.0));
filteredData.add(new VaultEntry(VaultEntryType.STRESS, TestFunctions.creatNewDateToCheckFor("2017.06.29-06:26"), 27.25));
filteredData.add(new VaultEntry(VaultEntryType.HEART_RATE_VARIABILITY, TestFunctions.creatNewDateToCheckFor("2017.06.29-06:26"), 50.0, 97.0));
filteredData.add(new VaultEntry(VaultEntryType.HEART_RATE, TestFunctions.creatNewDateToCheckFor("2017.06.29-06:26"), 62.0));
filteredData.add(new VaultEntry(VaultEntryType.SLEEP_DEEP, TestFunctions.creatNewDateToCheckFor("2017.06.29-06:29"), 11.0));
filteredData.add(new VaultEntry(VaultEntryType.HEART_RATE, TestFunctions.creatNewDateToCheckFor("2017.06.29-06:36"), 63.0));
filteredData.add(new VaultEntry(VaultEntryType.HEART_RATE_VARIABILITY, TestFunctions.creatNewDateToCheckFor("2017.06.29-06:36"), 50.0, 98.0));
filteredData.add(new VaultEntry(VaultEntryType.STRESS, TestFunctions.creatNewDateToCheckFor("2017.06.29-06:36"), 26.5));
filteredData.add(new VaultEntry(VaultEntryType.SLEEP_LIGHT, TestFunctions.creatNewDateToCheckFor("2017.06.29-06:40"), 15.0));
filteredData.add(new VaultEntry(VaultEntryType.HEART_RATE, TestFunctions.creatNewDateToCheckFor("2017.06.29-06:46"), 58.0));
filteredData.add(new VaultEntry(VaultEntryType.HEART_RATE_VARIABILITY, TestFunctions.creatNewDateToCheckFor("2017.06.29-06:46"), 50.0, 97.0));
filteredData.add(new VaultEntry(VaultEntryType.STRESS, TestFunctions.creatNewDateToCheckFor("2017.06.29-06:46"), 27.25));
filteredData.add(new VaultEntry(VaultEntryType.SLEEP_DEEP, TestFunctions.creatNewDateToCheckFor("2017.06.29-06:55"), 27.0));
filteredData.add(new VaultEntry(VaultEntryType.HEART_RATE, TestFunctions.creatNewDateToCheckFor("2017.06.29-06:56"), 59.0));
filteredData.add(new VaultEntry(VaultEntryType.BASAL_PROFILE, TestFunctions.creatNewDateToCheckFor("2017.06.29-07:00"), 1.15));
filteredData.add(new VaultEntry(VaultEntryType.HEART_RATE, TestFunctions.creatNewDateToCheckFor("2017.06.29-07:06"), 56.0));
List<Pair<Date, Date>> timeSeries = new ArrayList<>();
timeSeries.add(new Pair<>(TestFunctions.creatNewDateToCheckFor("2017.06.29-06:13"), TestFunctions.creatNewDateToCheckFor("2017.06.29-07:06")));
FilterResult checkForThisResult = new FilterResult(filteredData, timeSeries);
assertEquals(result.filteredData, checkForThisResult.filteredData);
assertEquals(result.timeSeries, checkForThisResult.timeSeries);
//assertEquals(result, checkForThisResult);
}
示例4: parse
import java.time.LocalTime; //導入方法依賴的package包/類
@Override
public LocalTime parse(final String value) {
// Very simple but straight forward parser, it use default format DateTimeFormatter.ISO_LOCAL_TIME
// so like: "10:15:30"
// hour:minutes:seconds
return LocalTime.parse(value);
}
示例5: deserialze
import java.time.LocalTime; //導入方法依賴的package包/類
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
JSONLexer lexer = parser.getLexer();
if (lexer.token() == 4) {
String text = lexer.stringVal();
lexer.nextToken();
if (type == LocalDateTime.class) {
return LocalDateTime.parse(text);
}
if (type == LocalDate.class) {
return LocalDate.parse(text);
}
if (type == LocalTime.class) {
return LocalTime.parse(text);
}
if (type == ZonedDateTime.class) {
return ZonedDateTime.parse(text);
}
if (type == OffsetDateTime.class) {
return OffsetDateTime.parse(text);
}
if (type == OffsetTime.class) {
return OffsetTime.parse(text);
}
if (type == ZoneId.class) {
return ZoneId.of(text);
}
if (type == Period.class) {
return Period.parse(text);
}
if (type == Duration.class) {
return Duration.parse(text);
}
if (type == Instant.class) {
return Instant.parse(text);
}
return null;
}
throw new UnsupportedOperationException();
}
示例6: main
import java.time.LocalTime; //導入方法依賴的package包/類
public static void main(String[] args) {
LocalTime movieStartTime = LocalTime.parse("21:00:00");
int commuteMin = 35;
LocalTime shreyaStartTime = movieStartTime.minusMinutes(commuteMin);
System.out.println("Start by" + shreyaStartTime + " from the office");
// second example
int worldRecord = 10;
LocalTime raceStartTime = LocalTime.of(8, 10, 55);
System.out.println("raceStartTime: " + raceStartTime);
LocalTime raceEndTime = LocalTime.of(8, 11, 11);
System.out.println("raceEndTime: " + raceEndTime);
System.out.println("raceEndTime plus 10 seconds: " + raceStartTime.plusSeconds(worldRecord));
if (raceStartTime.plusSeconds(worldRecord).isAfter(raceEndTime)) {
System.out.println("New world record");
} else {
System.out.println("Try harder");
}
// whith
LocalTime startTime = LocalTime.of(5, 7, 9);
if (startTime.getMinute() < 30) {
startTime = startTime.withMinute(0);
}
System.out.println(startTime);
}
示例7: factory_parse_validText
import java.time.LocalTime; //導入方法依賴的package包/類
@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);
}
示例8: parseLineToInfo
import java.time.LocalTime; //導入方法依賴的package包/類
private InfoSchema parseLineToInfo(String line, LocalDate localDate) {
String[] columns = line.split(" \\| ");
Matcher matcher = mjlogPattern.matcher(columns[3]);
if (matcher.find()) {
String id = matcher.group(1);
if (databaseService.existsIdInINFO(id)) return null;
boolean isSanma = columns[2].substring(0, 1).equals("三");
boolean isTonnan = columns[2].substring(2, 3).equals("南");
int minute = Integer.parseInt(columns[1]);
String[] playerAndScore = columns[4].split(" ");
String[] players = new String[4];
int[] scores = new int[4];
for (int i = 0; i < playerAndScore.length; i++) {
Matcher playerMatcher = playerPattern.matcher(playerAndScore[i]);
if (playerMatcher.find()) {
players[i] = playerMatcher.group(1);
scores[i] = (int) Float.parseFloat(playerMatcher.group(2));
}
}
LocalTime localTime = LocalTime.parse(columns[0]);
LocalDateTime localDateTime = LocalDateTime.of(localDate, localTime);
return new InfoSchema.Builder(id, isSanma, isTonnan, localDateTime,
players[0], players[1], players[2], players[3])
.minute(minute)
.firstScore(scores[0])
.secondScore(scores[1])
.thirdScore(scores[2])
.fourthScore(scores[3])
.build();
}
return null;
}
示例9: of
import java.time.LocalTime; //導入方法依賴的package包/類
public static TimeToken of(final String text) {
String time = text.toLowerCase();
if (NOW.equals(time)) {
return new TimeToken(LocalTime.now());
} else {
try {
// For hours < 10 (e.g., 1:30), the string will be less than 5 characters. LocalTime.parse(), though, requires, in its
// simplest form, HH:MM. If the string is less than 5 characters, we're going to add a zero at the beginning to put
// the string in the correct format hopefully. If the string is truly an invalid format (e.g., '130'), then
// LocalDate.parse() will fail, so there's no need to do sohpisticated validation here. We'll coerce the string as
// needed to the correct length, then let the JDK do the heavy lifting.
if (time.length() <5) {
time = "0" + time;
}
if (time.contains("am") || time.contains("pm")) {
final DateTimeFormatter formatter = new DateTimeFormatterBuilder()
.parseCaseInsensitive()
.appendPattern("h:mma")
.toFormatter();
return new TimeToken(LocalTime.parse(time.replaceAll(" ", ""), formatter));
} else {
return new TimeToken(LocalTime.parse(time));
}
} catch (DateTimeParseException ex) {
ex.printStackTrace();
throw new DateCalcException("Invalid time format: " + text);
}
}
}
示例10: factory_parse_illegalMinute
import java.time.LocalTime; //導入方法依賴的package包/類
@Test(expectedExceptions=DateTimeParseException.class)
public void factory_parse_illegalMinute() {
LocalTime.parse("12:60");
}
示例11: factory_parse_formatter_nullFormatter
import java.time.LocalTime; //導入方法依賴的package包/類
@Test(expectedExceptions=NullPointerException.class)
public void factory_parse_formatter_nullFormatter() {
LocalTime.parse("ANY", null);
}
示例12: factory_parse_formatter_nullText
import java.time.LocalTime; //導入方法依賴的package包/類
@Test(expectedExceptions=NullPointerException.class)
public void factory_parse_formatter_nullText() {
DateTimeFormatter f = DateTimeFormatter.ofPattern("H m s");
LocalTime.parse((String) null, f);
}
示例13: decodeText
import java.time.LocalTime; //導入方法依賴的package包/類
@Override
public LocalTime decodeText(int len, ByteBuf buff) {
CharSequence cs = buff.readCharSequence(len, StandardCharsets.UTF_8);
return LocalTime.parse(cs);
}
示例14: factory_parse_formatter
import java.time.LocalTime; //導入方法依賴的package包/類
@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));
}
示例15: factory_parse_illegalHour
import java.time.LocalTime; //導入方法依賴的package包/類
@Test(expectedExceptions=DateTimeParseException.class)
public void factory_parse_illegalHour() {
LocalTime.parse("25:00");
}