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


Java LocalDate.get方法代码示例

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


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

示例1: adjustInto

import java.time.LocalDate; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <R extends Temporal> R adjustInto(R temporal, long newValue) {
    if (isSupportedBy(temporal) == false) {
        throw new UnsupportedTemporalTypeException("Unsupported field: WeekBasedYear");
    }
    int newWby = range().checkValidIntValue(newValue, WEEK_BASED_YEAR);  // strict check
    LocalDate date = LocalDate.from(temporal);
    int dow = date.get(DAY_OF_WEEK);
    int week = getWeek(date);
    if (week == 53 && getWeekRange(newWby) == 52) {
        week = 52;
    }
    LocalDate resolved = LocalDate.of(newWby, 1, 4);  // 4th is guaranteed to be in week one
    int days = (dow - resolved.get(DAY_OF_WEEK)) + ((week - 1) * 7);
    resolved = resolved.plusDays(days);
    return (R) temporal.with(resolved);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:IsoFields.java

示例2: test_parse_resolve_localizedWoWBYDow

import java.time.LocalDate; //导入方法依赖的package包/类
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWoWBYDow(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate date = LocalDate.of(2012, 12, 31);
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField dowField = week.dayOfWeek();
    TemporalField wowbyField = week.weekOfWeekBasedYear();
    TemporalField yowbyField = week.weekBasedYear();

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

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

示例3: test_parse_resolve_localizedWoyDow

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

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

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

示例4: test_parse_resolve_localizedWoWBYDow_lenient

import java.time.LocalDate; //导入方法依赖的package包/类
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWoWBYDow_lenient(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate date = LocalDate.of(2012, 12, 31);
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField dowField = week.dayOfWeek();
    TemporalField wowbyField = week.weekOfWeekBasedYear();
    TemporalField yowbyField = week.weekBasedYear();

    for (int i = 1; i <= 60; i++) {
        DateTimeFormatter f = new DateTimeFormatterBuilder()
                .appendValue(yowbyField).appendLiteral(':')
                .appendValue(wowbyField).appendLiteral(':')
                .appendValue(dowField).toFormatter().withResolverStyle(LENIENT);
        int wowby = date.get(wowbyField);
        int dow = date.get(dowField);
        for (int j = wowby - 60; j < wowby + 60; j++) {
            String str = date.get(yowbyField) + ":" + j + ":" + dow;
            LocalDate parsed = LocalDate.parse(str, f);
            assertEquals(parsed, date.plusWeeks(j - wowby), " ::" + str + ": :" + i + "::" + j);
        }

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

示例5: test_parse_resolve_localizedWoy_lenient

import java.time.LocalDate; //导入方法依赖的package包/类
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWoy_lenient(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().withResolverStyle(LENIENT);
        int woy = date.get(woyField);
        int dow = date.get(DAY_OF_WEEK);
        for (int j = woy - 60; j < woy + 60; j++) {
            String str = date.getYear() + ":" + j + ":" + dow;
            LocalDate parsed = LocalDate.parse(str, f);
            assertEquals(parsed, date.plusWeeks(j - woy), " ::" + str + ": :" + i + "::" + j);
        }

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

示例6: test_parse_resolve_localizedWoyDow_lenient

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

    for (int i = 1; i <= 60; i++) {
        DateTimeFormatter f = new DateTimeFormatterBuilder()
                .appendValue(YEAR).appendLiteral(':')
                .appendValue(woyField).appendLiteral(':')
                .appendValue(dowField).toFormatter().withResolverStyle(LENIENT);
        int woy = date.get(woyField);
        int dow = date.get(dowField);
        for (int j = woy - 60; j < woy + 60; j++) {
            String str = date.getYear() + ":" + j + ":" + dow;
            LocalDate parsed = LocalDate.parse(str, f);
            assertEquals(parsed, date.plusWeeks(j - woy), " ::" + str + ": :" + i + "::" + j);
        }

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

示例7: test_parse_resolve_localizedWoWBY_lenient

import java.time.LocalDate; //导入方法依赖的package包/类
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWoWBY_lenient(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate date = LocalDate.of(2012, 12, 31);
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField wowbyField = week.weekOfWeekBasedYear();
    TemporalField yowbyField = week.weekBasedYear();

    for (int i = 1; i <= 60; i++) {
        DateTimeFormatter f = new DateTimeFormatterBuilder()
                .appendValue(yowbyField).appendLiteral(':')
                .appendValue(wowbyField).appendLiteral(':')
                .appendValue(DAY_OF_WEEK).toFormatter().withResolverStyle(LENIENT);
        int wowby = date.get(wowbyField);
        int dow = date.get(DAY_OF_WEEK);
        for (int j = wowby - 60; j < wowby + 60; j++) {
            String str = date.get(yowbyField) + ":" + j + ":" + dow;
            LocalDate parsed = LocalDate.parse(str, f);
            assertEquals(parsed, date.plusWeeks(j - wowby), " ::" + str + ": :" + i + "::" + j);
        }

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

示例8: test_weekOfMonthField

import java.time.LocalDate; //导入方法依赖的package包/类
@Test(dataProvider="weekFields")
public void test_weekOfMonthField(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate day = LocalDate.of(2012, 12, 31);  // Known to be ISO Monday
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField dowField = week.dayOfWeek();
    TemporalField womField = week.weekOfMonth();

    for (int i = 1; i <= 15; i++) {
        int actualDOW = day.get(dowField);
        int actualWOM = day.get(womField);

        // Verify that the combination of day of week and week of month can be used
        // to reconstruct the same date.
        LocalDate day1 = day.withDayOfMonth(1);
        int offset = - (day1.get(dowField) - 1);

        int week1 = day1.get(womField);
        if (week1 == 0) {
            // week of the 1st is partial; start with first full week
            offset += 7;
        }

        offset += actualDOW - 1;
        offset += (actualWOM - 1) * 7;
        LocalDate result = day1.plusDays(offset);

        assertEquals(result, day, "Incorrect dayOfWeek or weekOfMonth: "
                + String.format("%s, ISO Dow: %s, offset: %s, actualDOW: %s, actualWOM: %s, expected: %s, result: %s%n",
                week, day.getDayOfWeek(), offset, actualDOW, actualWOM, day, result));
        day = day.plusDays(1);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:33,代码来源:TCKWeekFields.java

示例9: test_weekOfWeekBasedYearField

import java.time.LocalDate; //导入方法依赖的package包/类
/**
 * Verify that the date can be reconstructed from the DOW, WeekOfWeekBasedYear,
 * and WeekBasedYear for every combination of start of week
 * and minimal days in week.
 * @param firstDayOfWeek the first day of the week
 * @param minDays the minimum number of days in the week
 */
@Test(dataProvider="weekFields")
public void test_weekOfWeekBasedYearField(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate day = LocalDate.of(2012, 12, 31);  // Known to be ISO Monday
    WeekFields weekDef = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField dowField = weekDef.dayOfWeek();
    TemporalField wowbyField = weekDef.weekOfWeekBasedYear();
    TemporalField yowbyField = weekDef.weekBasedYear();

    for (int i = 1; i <= 15; i++) {
        int actualDOW = day.get(dowField);
        int actualWOWBY = day.get(wowbyField);
        int actualYOWBY = day.get(yowbyField);

        // Verify that the combination of day of week and week of month can be used
        // to reconstruct the same date.
        LocalDate day1 = LocalDate.of(actualYOWBY, 1, 1);
        DayOfWeek isoDOW = day1.getDayOfWeek();
        int dow = (7 + isoDOW.getValue() - firstDayOfWeek.getValue()) % 7 + 1;

        int weekStart = Math.floorMod(1 - dow, 7);
        if (weekStart + 1 > weekDef.getMinimalDaysInFirstWeek()) {
            // The previous week has the minimum days in the current month to be a 'week'
            weekStart -= 7;
        }
        weekStart += actualDOW - 1;
        weekStart += (actualWOWBY - 1) * 7;
        LocalDate result = day1.plusDays(weekStart);

        assertEquals(result, day, "Incorrect dayOfWeek or weekOfYear "
                + String.format("%s, ISO Dow: %s, weekStart: %s, actualDOW: %s, actualWOWBY: %s, YearOfWBY: %d, expected day: %s, result: %s%n",
                weekDef, day.getDayOfWeek(), weekStart, actualDOW, actualWOWBY, actualYOWBY, day, result));
        day = day.plusDays(1);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:42,代码来源:TCKWeekFields.java

示例10: test_fieldRanges

import java.time.LocalDate; //导入方法依赖的package包/类
@Test(dataProvider="weekFields")
public void test_fieldRanges(DayOfWeek firstDayOfWeek, int minDays) {
    WeekFields weekDef = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField womField = weekDef.weekOfMonth();
    TemporalField woyField = weekDef.weekOfYear();

    LocalDate day = LocalDate.of(2012, 11, 30);
    LocalDate endDay = LocalDate.of(2013, 1, 2);
    while (day.isBefore(endDay)) {
        LocalDate last = day.with(DAY_OF_MONTH, day.lengthOfMonth());
        int lastWOM = last.get(womField);
        LocalDate first = day.with(DAY_OF_MONTH, 1);
        int firstWOM = first.get(womField);
        ValueRange rangeWOM = day.range(womField);
        assertEquals(rangeWOM.getMinimum(), firstWOM,
                "Range min should be same as WeekOfMonth for first day of month: "
                + first + ", " + weekDef);
        assertEquals(rangeWOM.getMaximum(), lastWOM,
                "Range max should be same as WeekOfMonth for last day of month: "
                + last + ", " + weekDef);

        last = day.with(DAY_OF_YEAR, day.lengthOfYear());
        int lastWOY = last.get(woyField);
        first = day.with(DAY_OF_YEAR, 1);
        int firstWOY = first.get(woyField);
        ValueRange rangeWOY = day.range(woyField);
        assertEquals(rangeWOY.getMinimum(), firstWOY,
                "Range min should be same as WeekOfYear for first day of Year: "
                + day + ", " + weekDef);
        assertEquals(rangeWOY.getMaximum(), lastWOY,
                "Range max should be same as WeekOfYear for last day of Year: "
                + day + ", " + weekDef);

        day = day.plusDays(1);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:37,代码来源:TCKWeekFields.java

示例11: test_withWeekOfWeekBasedYear

import java.time.LocalDate; //导入方法依赖的package包/类
@Test(dataProvider="weekFields")
public void test_withWeekOfWeekBasedYear(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate day = LocalDate.of(2012, 12, 31);
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField dowField = week.dayOfWeek();
    TemporalField wowbyField = week.weekOfWeekBasedYear();
    TemporalField yowbyField = week.weekBasedYear();

    int dowExpected = (day.get(dowField) - 1) % 7 + 1;
    LocalDate dowDate = day.with(dowField, dowExpected);
    int dowResult = dowDate.get(dowField);
    assertEquals(dowResult, dowExpected, "Localized DayOfWeek not correct; " + day + " -->" + dowDate);

    int weekExpected = day.get(wowbyField) + 1;
    ValueRange range = day.range(wowbyField);
    weekExpected = ((weekExpected - 1) % (int)range.getMaximum()) + 1;
    LocalDate weekDate = day.with(wowbyField, weekExpected);
    int weekResult = weekDate.get(wowbyField);
    assertEquals(weekResult, weekExpected, "Localized WeekOfWeekBasedYear not correct; " + day + " -->" + weekDate);

    int yearExpected = day.get(yowbyField) + 1;

    LocalDate yearDate = day.with(yowbyField, yearExpected);
    int yearResult = yearDate.get(yowbyField);
    assertEquals(yearResult, yearExpected, "Localized WeekBasedYear not correct; " + day  + " --> " + yearDate);

    range = yearDate.range(wowbyField);
    weekExpected = Math.min(day.get(wowbyField), (int)range.getMaximum());

    int weekActual = yearDate.get(wowbyField);
    assertEquals(weekActual, weekExpected, "Localized WeekOfWeekBasedYear week should not change; " + day + " --> " + yearDate + ", actual: " + weekActual + ", weekExpected: " + weekExpected);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:33,代码来源:TCKWeekFields.java

示例12: updateView

import java.time.LocalDate; //导入方法依赖的package包/类
private void updateView() {
    lastSelectedDate = null;

    YearMonthView view = getSkinnable();
    YearMonth yearMonth = view.getYearMonth();

    displayedYearMonth = yearMonth;

    boolean currentYearMonth = getSkinnable().getYearMonth().equals(YearMonth.from(getSkinnable().getToday()));

    monthLabel.getStyleClass().remove(CURRENT_DATE_LABEL);
    yearLabel.getStyleClass().remove(CURRENT_DATE_LABEL);

    if (currentYearMonth && view.isShowToday()) {
        monthLabel.getStyleClass().add(CURRENT_DATE_LABEL);
        yearLabel.getStyleClass().add(CURRENT_DATE_LABEL);
    }

    monthLabel.setText(DateTimeFormatter.ofPattern(Messages.getString("YearMonthViewSkin.MONTH_FORMAT")).format(yearMonth)); //$NON-NLS-1$
    yearLabel.setText(DateTimeFormatter.ofPattern(Messages.getString("YearMonthViewSkin.YEAR_FORMAT")).format(yearMonth)); //$NON-NLS-1$

    // update the week days (mon, tues, wed, ....)

    DayOfWeek dayOfWeek = view.getFirstDayOfWeek();
    for (int i = 0; i < 7; i++) {
        if (view.isShowToday()) {
            if (currentYearMonth) {
                dayOfWeekLabels[i].getStyleClass().add(CURRENT_DATE_BORDER);
            }
            if (currentYearMonth && view.getToday().getDayOfWeek().equals(dayOfWeek)) {
                dayOfWeekLabels[i].getStyleClass().add(CURRENT_DATE_LABEL);
            }
        }
    }


    // update the days (1 .. 31) plus padding days

    final DayOfWeek firstDayOfWeek = getSkinnable().getFirstDayOfWeek();
    LocalDate date = Util.adjustToFirstDayOfWeek(getLoadStartDate(), firstDayOfWeek);

    if (getSkinnable().isShowWeekNumbers()) {
        for (int i = 0; i < 6; i++) {
            int weekOfYear = date.get(getSkinnable().getWeekFields().weekOfYear());
            weekNumberLabels[i].setText(Integer.toString(weekOfYear));
            date = date.plusWeeks(1);
        }
    }

    date = Util.adjustToFirstDayOfWeek(getLoadStartDate(), firstDayOfWeek);

    for (int row = 0; row < 6; row++) {
        for (int col = 0; col < 7; col++) {
            LocalDate localDate = LocalDate.from(date);

            YearMonthView.DateCell cell = cellsMap.get(getKey(row, col));
            cell.setDate(localDate);
            cell.getStyleClass().removeAll(TODAY, DAY_OF_MONTH_LABEL, DAY_NOT_OF_MONTH_LABEL, WEEKEND_DAY, SELECTED_MONTH_DATE);

            if (getSkinnable().getSelectedDates().contains(date)) {
                cell.getStyleClass().add(SELECTED_MONTH_DATE); //$NON-NLS-1$
            }

            if (YearMonth.from(date).equals(YearMonth.from(getSkinnable().getDate()))) {
                if (getSkinnable().isShowToday() && date.equals(getSkinnable().getToday())) {
                    cell.getStyleClass().add(TODAY);
                } else {
                    cell.getStyleClass().add(DAY_OF_MONTH_LABEL); //$NON-NLS-1$
                }
            } else {
                cell.getStyleClass().add(DAY_NOT_OF_MONTH_LABEL); //$NON-NLS-1$
            }

            if (view.getWeekendDays().contains(date.getDayOfWeek())) {
                cell.getStyleClass().add(WEEKEND_DAY); //$NON-NLS-1$
            }

            date = date.plusDays(1);
        }
    }
}
 
开发者ID:dlemmermann,项目名称:CalendarFX,代码行数:82,代码来源:YearMonthViewSkin.java

示例13: getWeekday

import java.time.LocalDate; //导入方法依赖的package包/类
private int getWeekday(LocalDate date) {
    return date.get(weekFields.dayOfWeek()) - 1;
}
 
开发者ID:tbressler,项目名称:waterrower-workout,代码行数:4,代码来源:ActivityDiagramSkin.java

示例14: getWeek

import java.time.LocalDate; //导入方法依赖的package包/类
private int getWeek(LocalDate date) {
    return date.get(weekFields.weekOfWeekBasedYear());
}
 
开发者ID:tbressler,项目名称:waterrower-workout,代码行数:4,代码来源:ActivityDiagramSkin.java


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