当前位置: 首页>>代码示例>>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;未经允许,请勿转载。