當前位置: 首頁>>代碼示例>>Java>>正文


Java LocalTime.parse方法代碼示例

本文整理匯總了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);
}
 
開發者ID:tiweGH,項目名稱:OpenDiabetes,代碼行數:23,代碼來源:TimePointFilterTest.java

示例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");


}
 
開發者ID:huby,項目名稱:java-se8-oca-study-guide,代碼行數:21,代碼來源:Main.java

示例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);
}
 
開發者ID:tiweGH,項目名稱:OpenDiabetes,代碼行數:38,代碼來源:TimePointFilterTest.java

示例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);
}
 
開發者ID:Blackdread,項目名稱:filter-sort-jooq-api,代碼行數:8,代碼來源:FilterParserTime.java

示例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();
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:40,代碼來源:Jdk8DateCodec.java

示例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);

}
 
開發者ID:huby,項目名稱:java-se8-oca-study-guide,代碼行數:29,代碼來源:Main.java

示例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);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:10,代碼來源:TCKLocalTime.java

示例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;
}
 
開發者ID:CrazyBBB,項目名稱:tenhou-visualizer,代碼行數:35,代碼來源:DownloadYearTask.java

示例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);
        }
    }
}
 
開發者ID:PacktPublishing,項目名稱:Java-9-Programming-Blueprints,代碼行數:30,代碼來源:TimeToken.java

示例10: factory_parse_illegalMinute

import java.time.LocalTime; //導入方法依賴的package包/類
@Test(expectedExceptions=DateTimeParseException.class)
public void factory_parse_illegalMinute() {
    LocalTime.parse("12:60");
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:5,代碼來源:TCKLocalTime.java

示例11: factory_parse_formatter_nullFormatter

import java.time.LocalTime; //導入方法依賴的package包/類
@Test(expectedExceptions=NullPointerException.class)
public void factory_parse_formatter_nullFormatter() {
    LocalTime.parse("ANY", null);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:5,代碼來源:TCKLocalTime.java

示例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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:6,代碼來源:TCKLocalTime.java

示例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);
}
 
開發者ID:vietj,項目名稱:reactive-pg-client,代碼行數:6,代碼來源:DataType.java

示例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));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:7,代碼來源:TCKLocalTime.java

示例15: factory_parse_illegalHour

import java.time.LocalTime; //導入方法依賴的package包/類
@Test(expectedExceptions=DateTimeParseException.class)
public void factory_parse_illegalHour() {
    LocalTime.parse("25:00");
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:5,代碼來源:TCKLocalTime.java


注:本文中的java.time.LocalTime.parse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。