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


Java LocalDateTime.with方法代码示例

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


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

示例1: testRoundingDate

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void testRoundingDate() {
    int month = randomIntBetween(1, 12);
    int day = randomIntBetween(1, 28);
    int hourOfDay = randomIntBetween(0, 23);
    int minute = randomIntBetween(0, 59);
    int year = randomIntBetween(2016, 2025);
    LocalDateTime dateTime = LocalDateTime.of(year, month, day, hourOfDay, minute);
    LocalDateTime roundedDate = Generator.roundEndDateToTheNextHalfHour(dateTime);
    assertThat(roundedDate.isAfter(dateTime), is(true));

    LocalDateTime expectedDate = dateTime.with(temporal -> {
        int currentMinute = temporal.get(ChronoField.MINUTE_OF_HOUR);
        if (currentMinute >= 30) {
            return temporal.plus(60 - currentMinute, ChronoUnit.MINUTES);
        } else {
            return temporal.plus(30 - currentMinute, ChronoUnit.MINUTES);
        }
    });

    assertThat(roundedDate, is(expectedDate));
}
 
开发者ID:spinscale,项目名称:maxcube-java,代码行数:23,代码来源:GeneratorTest.java

示例2: getDateRelativeToToday

import java.time.LocalDateTime; //导入方法依赖的package包/类
private LocalDateTime getDateRelativeToToday(ChronoField field, int buffer) {
    LocalDateTime date = LocalDateTime.now();
    // want a date with a buffer either side of it and also not including the date itself
    int gap = 2 * buffer + 1;
    int max = (int)field.range().getSmallestMaximum();
    int rand = getRandomInt(1, max - gap);
    int value = rand >= date.get(field) - buffer ? rand + gap : rand;
    LocalDateTime relativeDate = date.with(field, value);

    // Adding logging to help with some spurious errors...
    log.info("Date: " + date + " rand: " + rand + " value: " + value + " Picked date: " + relativeDate);

    return relativeDate;
}
 
开发者ID:NHS-digital-website,项目名称:hippo,代码行数:15,代码来源:CmsSteps.java

示例3: test_appendText2arg_format

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(dataProvider="printText")
public void test_appendText2arg_format(TemporalField field, TextStyle style, int value, String expected) throws Exception {
    DateTimeFormatter f = builder.appendText(field, style).toFormatter(Locale.ENGLISH);
    LocalDateTime dt = LocalDateTime.of(2010, 1, 1, 0, 0);
    dt = dt.with(field, value);
    String text = f.format(dt);
    assertEquals(text, expected);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:9,代码来源:TCKDateTimeTextPrinting.java

示例4: test_appendText1arg_format

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(dataProvider="printText")
public void test_appendText1arg_format(TemporalField field, TextStyle style, int value, String expected) throws Exception {
    if (style == TextStyle.FULL) {
        DateTimeFormatter f = builder.appendText(field).toFormatter(Locale.ENGLISH);
        LocalDateTime dt = LocalDateTime.of(2010, 1, 1, 0, 0);
        dt = dt.with(field, value);
        String text = f.format(dt);
        assertEquals(text, expected);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:TCKDateTimeTextPrinting.java

示例5: adjustField

import java.time.LocalDateTime; //导入方法依赖的package包/类
private static LocalDateTime adjustField(LocalDateTime time, ChronoField field, int stepRate) {
    return time.with(field, time.get(field) - time.get(field) % stepRate);
}
 
开发者ID:dlemmermann,项目名称:CalendarFX,代码行数:4,代码来源:Util.java


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