当前位置: 首页>>代码示例>>Java>>正文


Java LocalDate类代码示例

本文整理汇总了Java中java.time.LocalDate的典型用法代码示例。如果您正苦于以下问题:Java LocalDate类的具体用法?Java LocalDate怎么用?Java LocalDate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


LocalDate类属于java.time包,在下文中一共展示了LocalDate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: populateMonthPane

import java.time.LocalDate; //导入依赖的package包/类
/**
 * Creates and positions every node onto the GridPane for the given month and year.
 * Uses 7 (weekdays) columns and (max.) 6 rows (weeks). The rows and columns are created on fly or
 * are reused.
 *
 * @param monthPane The GradPane that is used for populating the DayNodes.
 * @param month The month that should be displayed.
 * @param year The year that should be displayed.
 */
private void populateMonthPane(GridPane monthPane, Month month, int year) {
    monthPane.getChildren().clear();

    int currentRow = 0;
    for(LocalDate d = LocalDate.of(year, month, 1);
            d.getMonthValue() == month.getValue();
            d = d.plusDays(1)) {
        Node dayNode = renderDayItem(d);
        final LocalDate currentDate = d;
        dayNode.setOnMouseClicked(event -> selectedDateProperty.set(currentDate));

        int column = d.getDayOfWeek().getValue();
        monthPane.add(dayNode, column, currentRow);

        if(column == 7) {
            currentRow++;
        }
    }
}
 
开发者ID:Jibbow,项目名称:FastisFX,代码行数:29,代码来源:DayChooser.java

示例2: run

import java.time.LocalDate; //导入依赖的package包/类
@Override
@SuppressWarnings("InfiniteLoopStatement")
public void run() {
    while (true) {
        Platform.runLater(() -> {
            calendarView.setToday(LocalDate.now());
            calendarView.setTime(LocalTime.now());
        });

        try {
            sleep(TEN_SECONDS);
        } catch (InterruptedException e) {
            // Do nothing
        }
    }
}
 
开发者ID:dlemmermann,项目名称:CalendarFX,代码行数:17,代码来源:CalendarViewTimeUpdateThread.java

示例3: data_atEndOfMonth

import java.time.LocalDate; //导入依赖的package包/类
@DataProvider(name="atEndOfMonth")
Object[][] data_atEndOfMonth() {
    return new Object[][] {
            {YearMonth.of(2008, 1), LocalDate.of(2008, 1, 31)},
            {YearMonth.of(2008, 2), LocalDate.of(2008, 2, 29)},
            {YearMonth.of(2008, 3), LocalDate.of(2008, 3, 31)},
            {YearMonth.of(2008, 4), LocalDate.of(2008, 4, 30)},
            {YearMonth.of(2008, 5), LocalDate.of(2008, 5, 31)},
            {YearMonth.of(2008, 6), LocalDate.of(2008, 6, 30)},
            {YearMonth.of(2008, 12), LocalDate.of(2008, 12, 31)},

            {YearMonth.of(2009, 1), LocalDate.of(2009, 1, 31)},
            {YearMonth.of(2009, 2), LocalDate.of(2009, 2, 28)},
            {YearMonth.of(2009, 3), LocalDate.of(2009, 3, 31)},
            {YearMonth.of(2009, 4), LocalDate.of(2009, 4, 30)},
            {YearMonth.of(2009, 5), LocalDate.of(2009, 5, 31)},
            {YearMonth.of(2009, 6), LocalDate.of(2009, 6, 30)},
            {YearMonth.of(2009, 12), LocalDate.of(2009, 12, 31)},
    };
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:TCKYearMonth.java

示例4: test_badTemporalFieldChrono

import java.time.LocalDate; //导入依赖的package包/类
@Test(dataProvider="calendars")
public void test_badTemporalFieldChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoLocalDate date = chrono.date(refDate);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDate date2 = chrono2.date(refDate);
        TemporalField adjuster = new FixedTemporalField(date2);
        if (chrono != chrono2) {
            try {
                date.with(adjuster, 1);
                Assert.fail("TemporalField doSet should have thrown a ClassCastException" + date.getClass()
                        + ", can not be cast to " + date2.getClass());
            } catch (ClassCastException cce) {
                // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDate result = date.with(adjuster, 1);
            assertEquals(result, date2, "TemporalField doSet failed to replace date");
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:24,代码来源:TCKChronoLocalDate.java

示例5: getText

import java.time.LocalDate; //导入依赖的package包/类
@Test public void getText() {
    DatePicker datePicker = (DatePicker) getPrimaryStage().getScene().getRoot().lookup(".date-picker");
    LoggingRecorder lr = new LoggingRecorder();
    List<String> text = new ArrayList<>();
    RFXDatePicker rfxDatePicker = new RFXDatePicker(datePicker, null, null, lr);
    Platform.runLater(() -> {
        datePicker.setValue(LocalDate.now());
        text.add(rfxDatePicker._getText());
    });
    new Wait("Waiting for date picker text.") {
        @Override public boolean until() {
            return text.size() > 0;
        }
    };
    AssertJUnit.assertEquals(datePicker.getConverter().toString(LocalDate.now()), text.get(0));
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:17,代码来源:RFXDatePickerTest.java

示例6: test_badPlusAdjusterChrono

import java.time.LocalDate; //导入依赖的package包/类
@Test(dataProvider="calendars")
public void test_badPlusAdjusterChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
        TemporalAmount adjuster = new FixedAdjuster(cdt2);
        if (chrono != chrono2) {
            try {
                cdt.plus(adjuster);
                Assert.fail("WithAdjuster should have thrown a ClassCastException, "
                        + "required: " + cdt + ", supplied: " + cdt2);
            } catch (ClassCastException cce) {
                // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDateTime<?> result = cdt.plus(adjuster);
            assertEquals(result, cdt2, "WithAdjuster failed to replace date time");
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:24,代码来源:TCKChronoLocalDateTime.java

示例7: getSupervisionList

import java.time.LocalDate; //导入依赖的package包/类
@Override
public List<SupervisionDetails> getSupervisionList() {
    List<SupervisionDetails> supervisionDetails = new ArrayList<>();
    List<Tractor> tractorList = this.getAllTractors();
    for(Tractor tractor : tractorList){
        if(DateUtils.getDaysDifference(tractor.getDateOfSupervision(), LocalDate.now()) <= 30){
            SupervisionDetails details = new SupervisionDetails();
            details.setDateOfSupervision(tractor.getDateOfSupervision());
            details.setDaysRemaining(DateUtils.getDaysDifference(tractor.getDateOfSupervision(),LocalDate.now()));
            details.setManufacturer(tractor.getManufacturer());
            details.setType(tractor.getType());
            details.setPlateNo(tractor.getPlateNumber());
            supervisionDetails.add(details);
        }
    }
    logger.debug("in 30 days of supervision: {}",supervisionDetails.size());
    return supervisionDetails;
}
 
开发者ID:Chrams,项目名称:openfleet,代码行数:19,代码来源:TractorServiceImpl.java

示例8: m5InstantOfNextFrameShouldReturnTheNextInstantThatsMinutesAreAMultipleOfFive

import java.time.LocalDate; //导入依赖的package包/类
/**
 * {@link M5#instantOfNextFrame(Instant)} should return the instant with the minutes set to the earliest possible
 * {@link Instant} that is later than the {@link Instant} past and thats minutes are a multiple of 5.
 */
@Test
public void m5InstantOfNextFrameShouldReturnTheNextInstantThatsMinutesAreAMultipleOfFive() {
    final M5 cut = new M5();

    assertThat(cut.instantOfNextFrame(LocalDate.of(2074, Month.MARCH, 30).atTime(20, 4, 0, 0).toInstant(UTC)))
            .isEqualTo(LocalDate.of(2074, Month.MARCH, 30).atTime(20, 5, 0, 0).toInstant(UTC));
    assertThat(cut.instantOfNextFrame(LocalDate.of(1999, Month.APRIL, 23).atTime(15, 59, 0, 0).toInstant(UTC)))
            .isEqualTo(LocalDate.of(1999, Month.APRIL, 23).atTime(16, 0, 0, 0).toInstant(UTC));
    assertThat(cut.instantOfNextFrame(LocalDate.of(2007, Month.SEPTEMBER, 6).atTime(17, 29, 0, 0).toInstant(UTC)))
            .isEqualTo(LocalDate.of(2007, Month.SEPTEMBER, 6).atTime(17, 30, 0, 0).toInstant(UTC));
    assertThat(cut.instantOfNextFrame(LocalDate.of(2021, Month.JUNE, 8).atTime(8, 34, 0, 0).toInstant(UTC)))
            .isEqualTo(LocalDate.of(2021, Month.JUNE, 8).atTime(8, 35, 0, 0).toInstant(UTC));

    assertThat(cut.instantOfNextFrame(LocalDate.of(1570, Month.NOVEMBER, 24).atTime(23, 7, 0, 0).toInstant(UTC)))
            .isEqualTo(LocalDate.of(1570, Month.NOVEMBER, 24).atTime(23, 10, 0, 0).toInstant(UTC));
    assertThat(cut.instantOfNextFrame(LocalDate.of(2047, Month.JANUARY, 24).atTime(16, 15, 0, 0).toInstant(UTC)))
            .isEqualTo(LocalDate.of(2047, Month.JANUARY, 24).atTime(16, 20, 0, 0).toInstant(UTC));
    assertThat(cut.instantOfNextFrame(LocalDate.of(1989, Month.JUNE, 10).atTime(15, 14, 37, 0).toInstant(UTC)))
            .isEqualTo(LocalDate.of(1989, Month.JUNE, 10).atTime(15, 15, 0, 0).toInstant(UTC));
    assertThat(cut.instantOfNextFrame(LocalDate.of(2006, Month.AUGUST, 10).atTime(3, 29, 0, 7521).toInstant(UTC)))
            .isEqualTo(LocalDate.of(2006, Month.AUGUST, 10).atTime(3, 30, 0, 0).toInstant(UTC));
    assertThat(
            cut.instantOfNextFrame(LocalDate.of(3057, Month.NOVEMBER, 10).atTime(8, 54, 12, 45720).toInstant(UTC)))
            .isEqualTo(LocalDate.of(3057, Month.NOVEMBER, 10).atTime(8, 55, 0, 0).toInstant(UTC));
}
 
开发者ID:rbi,项目名称:trading4j,代码行数:30,代码来源:M5Test.java

示例9: test_parse_resolve_localizedWoy

import java.time.LocalDate; //导入依赖的package包/类
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWoy(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate date = LocalDate.of(2012, 12, 15);
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField woyField = week.weekOfYear();

    for (int i = 1; i <= 60; i++) {
        DateTimeFormatter f = new DateTimeFormatterBuilder()
                .appendValue(YEAR).appendLiteral(':')
                .appendValue(woyField).appendLiteral(':')
                .appendValue(DAY_OF_WEEK).toFormatter();
        String str = date.getYear() + ":" +
                date.get(woyField) + ":" + date.get(DAY_OF_WEEK);
        LocalDate parsed = LocalDate.parse(str, f);
        assertEquals(parsed, date, " :: " + str + " " + i);

        date = date.plusDays(1);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:TCKWeekFields.java

示例10: pastWeather

import java.time.LocalDate; //导入依赖的package包/类
/**
 * E.g. http://api.worldweatheronline.com/free/v2/search.ashx?query=oporto&format=tab&key=*****
 */
public Iterable<WeatherInfo> pastWeather(
        double lat,
        double log,
        LocalDate from,
        LocalDate to
) {
    String query = lat + "," + log;
    String path = WEATHER_HOST + WEATHER_PAST +
            String.format(WEATHER_PAST_ARGS, query, from, to, WEATHER_TOKEN);
    List<WeatherInfo> res = new ArrayList<>();
    Iterator<String> iter = req.getContent(path).iterator();
    while(iter.next().startsWith("#")) { }
    iter.next(); // Skip line: Not Available
    while(iter.hasNext()) {
        String line = iter.next(); // Skip Daily Info
        res.add(WeatherInfo.valueOf(line));
        if(iter.hasNext()) iter.next();
    }
    return res;
}
 
开发者ID:isel-leic-mpd,项目名称:mpd-2017-i41d,代码行数:24,代码来源:WeatherWebApi.java

示例11: shouldSelectMultipleDates

import java.time.LocalDate; //导入依赖的package包/类
@Test
public void shouldSelectMultipleDates() {
    // Given
    LocalDate now = LocalDate.now();
    LocalDate tomorrow = now.plusDays(1);
    LocalDate dayAfterTomorrow = tomorrow.plusDays(1);
    LocalDate oneYearAfter = dayAfterTomorrow.plusYears(1);
    DateSelectionModel model = new DateSelectionModel();
    model.setSelectionMode(SelectionMode.MULTIPLE_DATES);

    // When
    model.selectRange(now, dayAfterTomorrow);
    model.select(oneYearAfter);

    // Then
    assertFalse(model.isEmpty());
    assertThat(model.getSelectedDates(), is(not(empty())));
    assertThat(model.getSelectedDates().size(), is(equalTo(4)));
    assertThat(model.getSelectedDates(), contains(now, tomorrow, dayAfterTomorrow, oneYearAfter));
    assertThat(model.getLastSelected(), is(equalTo(oneYearAfter)));
    assertTrue(model.isSelected(now));
    assertTrue(model.isSelected(tomorrow));
    assertTrue(model.isSelected(dayAfterTomorrow));
    assertTrue(model.isSelected(oneYearAfter));
}
 
开发者ID:dlemmermann,项目名称:CalendarFX,代码行数:26,代码来源:DateSelectionModelTests.java

示例12: test_reducedWithLateChronoChange

import java.time.LocalDate; //导入依赖的package包/类
@Test
public void test_reducedWithLateChronoChange() {
    ThaiBuddhistDate date = ThaiBuddhistDate.of(2543, 1, 1);
    DateTimeFormatter df
            = new DateTimeFormatterBuilder()
                    .appendValueReduced(YEAR, 2, 2, LocalDate.of(2000, 1, 1))
                    .appendLiteral(" ")
                    .appendChronologyId()
            .toFormatter();
    int expected = date.get(YEAR);
    String input = df.format(date);

    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor parsed = df.parseUnresolved(input, pos);
    assertEquals(pos.getIndex(), input.length(), "Input not parsed completely");
    assertEquals(pos.getErrorIndex(), -1, "Error index should be -1 (no-error)");
    int actual = parsed.get(YEAR);
    assertEquals(actual, expected,
            String.format("Wrong date parsed, chrono: %s, input: %s",
            parsed.query(TemporalQueries.chronology()), input));

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:TestReducedParser.java

示例13: processShortages

import java.time.LocalDate; //导入依赖的package包/类
public void processShortages(String productRefNo) {
    LocalDate today = LocalDate.now(clock);
    CurrentStock currentStock = stockService.getCurrentStock(productRefNo);
    List<ShortageEntity> shortages = ShortageFinder.findShortages(
            today, confShortagePredictionDaysAhead,
            currentStock,
            productionDao.findFromTime(productRefNo, today.atStartOfDay()),
            demandDao.findFrom(today.atStartOfDay(), productRefNo)
    );

    List<ShortageEntity> previous = shortageDao.getForProduct(productRefNo);
    if (shortages != null && !shortages.equals(previous)) {
        notificationService.alertPlanner(shortages);
        if (currentStock.getLocked() > 0 &&
                shortages.get(0).getAtDay()
                        .isBefore(today.plusDays(confIncreaseQATaskPriorityInDays))) {
            jiraService.increasePriorityFor(productRefNo);
        }
    }
    if (shortages.isEmpty() && !previous.isEmpty()) {
        shortageDao.delete(productRefNo);
    }
}
 
开发者ID:michal-michaluk,项目名称:ddd-refactoring,代码行数:24,代码来源:WarehouseServiceImpl.java

示例14: registerConfigProducer

import java.time.LocalDate; //导入依赖的package包/类
public void registerConfigProducer(@Observes AfterBeanDiscovery abd, BeanManager bm) {
    // excludes type that are already produced by ConfigProducer
    Set<Class> types = injectionPoints.stream()
            .filter(ip -> ip.getType() instanceof Class
                    && ip.getType() != String.class
                    && ip.getType() != Boolean.class
                    && ip.getType() != Boolean.TYPE
                    && ip.getType() != Integer.class
                    && ip.getType() != Integer.TYPE
                    && ip.getType() != Long.class
                    && ip.getType() != Long.TYPE
                    && ip.getType() != Float.class
                    && ip.getType() != Float.TYPE
                    && ip.getType() != Double.class
                    && ip.getType() != Double.TYPE
                    && ip.getType() != Duration.class
                    && ip.getType() != LocalDate.class
                    && ip.getType() != LocalTime.class
                    && ip.getType() != LocalDateTime.class)
            .map(ip -> (Class) ip.getType())
            .collect(Collectors.toSet());
    types.forEach(type -> abd.addBean(new ConfigInjectionBean(bm, type)));
}
 
开发者ID:wildfly-extras,项目名称:wildfly-microprofile-config,代码行数:24,代码来源:ConfigExtension.java

示例15: parseLastRaceDate

import java.time.LocalDate; //导入依赖的package包/类
private static LocalDate parseLastRaceDate(List<ChartCharacter> chartCharacters) {
    ChartCharacter lastChartCharacter = null;
    List<ChartCharacter> lastRaceDateCharacters = new ArrayList<>();
    for (ChartCharacter columnCharacter : chartCharacters) {
        // handle when lastChartCharacter race number is unknown
        if (columnCharacter.getFontSize() == 5 ||
                spaceDetected(lastChartCharacter, columnCharacter)) {
            break;
        }
        lastRaceDateCharacters.add(columnCharacter);
        lastChartCharacter = columnCharacter;
    }
    String lastRaceDateText = Chart.convertToText(lastRaceDateCharacters);
    // so that 97 becomes 1997 and 03 becomes 2003
    DateTimeFormatter dateTimeFormatter = new DateTimeFormatterBuilder()
            .appendPattern("dMMM")
            .appendValueReduced(ChronoField.YEAR_OF_ERA, 2, 2, LocalDate.now().minusYears(80))
            .toFormatter();
    LocalDate lastRaceDate = LocalDate.parse(lastRaceDateText, dateTimeFormatter);

    chartCharacters.removeAll(lastRaceDateCharacters);

    return lastRaceDate;
}
 
开发者ID:robinhowlett,项目名称:chart-parser,代码行数:25,代码来源:LastRaced.java


注:本文中的java.time.LocalDate类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。