當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。