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


Java LocalDate.withDayOfMonth方法代码示例

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


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

示例1: split

import java.time.LocalDate; //导入方法依赖的package包/类
/**
 * Splits the given period into multiple slices of one month long.
 *
 * @param start the start of the period.
 * @param end   the end of the period.
 * @return The list of slices result of the splitting.
 */
public static List<Slice> split(LocalDate start, LocalDate end) {
    Objects.requireNonNull(start);
    Objects.requireNonNull(end);
    Preconditions.checkArgument(!start.isAfter(end));

    List<Slice> slices = Lists.newArrayList();

    LocalDate startOfMonth = start.withDayOfMonth(1);
    LocalDate endOfMonth = YearMonth.from(end).atEndOfMonth();

    do {
        slices.add(new Slice(startOfMonth, YearMonth.from(startOfMonth).atEndOfMonth()));
        startOfMonth = startOfMonth.plus(1, ChronoUnit.MONTHS);
    }
    while (startOfMonth.isBefore(endOfMonth) || startOfMonth.isEqual(endOfMonth));

    return slices;
}
 
开发者ID:dlemmermann,项目名称:CalendarFX,代码行数:26,代码来源:Slice.java

示例2: 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

示例3: next

import java.time.LocalDate; //导入方法依赖的package包/类
private LocalDate next(LocalDate date) {
    int newDayOfMonth = date.getDayOfMonth() + 1;
    if (newDayOfMonth <= date.getMonth().length(isIsoLeap(date.getYear()))) {
        return date.withDayOfMonth(newDayOfMonth);
    }
    date = date.withDayOfMonth(1);
    if (date.getMonth() == Month.DECEMBER) {
        date = date.withYear(date.getYear() + 1);
    }
    return date.with(date.getMonth().plus(1));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:12,代码来源:TCKLocalDate.java

示例4: previous

import java.time.LocalDate; //导入方法依赖的package包/类
private LocalDate previous(LocalDate date) {
    int newDayOfMonth = date.getDayOfMonth() - 1;
    if (newDayOfMonth > 0) {
        return date.withDayOfMonth(newDayOfMonth);
    }
    date = date.with(date.getMonth().minus(1));
    if (date.getMonth() == Month.DECEMBER) {
        date = date.withYear(date.getYear() - 1);
    }
    return date.withDayOfMonth(date.getMonth().length(isIsoLeap(date.getYear())));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:12,代码来源:TCKLocalDate.java


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