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


Java ZonedDateTime.with方法代码示例

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


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

示例1: add

import java.time.ZonedDateTime; //导入方法依赖的package包/类
public void add(EntryViewBase<?> view) {
    if (entryViews == null) {
        entryViews = new ArrayList<>();
    }

    entryViews.add(view);

    Entry<?> entry = view.getEntry();

    ZonedDateTime entryStartTime = entry.getStartAsZonedDateTime();
    ZonedDateTime entryEndTime = entry.getEndAsZonedDateTime();

    if (entry.isFullDay()) {
        entryStartTime = entryStartTime.with(LocalTime.MIN);
        entryEndTime = entryEndTime.with(LocalTime.MAX);
    }

    if (startTime == null || entryStartTime.isBefore(startTime)) {
        startTime = entryStartTime;
    }

    if (endTime == null || entryEndTime.isAfter(endTime)) {
        endTime = entryEndTime;
    }
}
 
开发者ID:dlemmermann,项目名称:CalendarFX,代码行数:26,代码来源:Cluster.java

示例2: test_with_adjuster_LocalDate_retainOffset1

import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void test_with_adjuster_LocalDate_retainOffset1() {
    ZoneId newYork = ZoneId.of("America/New_York");
    LocalDateTime ldt = LocalDateTime.of(2008, 11, 1, 1, 30);
    ZonedDateTime base = ZonedDateTime.of(ldt, newYork);
    assertEquals(base.getOffset(), ZoneOffset.ofHours(-4));
    ZonedDateTime test = base.with(LocalDate.of(2008, 11, 2));
    assertEquals(test.getOffset(), ZoneOffset.ofHours(-4));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:TCKZonedDateTime.java

示例3: test_with_adjuster_OffsetTime_invalidOffsetIgnored1

import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void test_with_adjuster_OffsetTime_invalidOffsetIgnored1() {
    // OT has invalid offset for ZDT, so only LT is set
    OffsetTime ot = OffsetTime.of(0, 50, 30, 40, OFFSET_0130);
    ZonedDateTime zdt = dateTime(2008, 10, 26, 2, 30, 0, 0, OFFSET_0200, ZONE_PARIS);  // earlier part of overlap
    ZonedDateTime test = zdt.with(ot);
    assertEquals(test.toLocalDateTime(), dateTime(2008, 10, 26, 0, 50, 30, 40));
    assertEquals(test.getOffset(), OFFSET_0200);  // offset not adjusted
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:TCKZonedDateTime.java

示例4: test_with_adjuster_OffsetTime_validOffsetIntoOverlap2

import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void test_with_adjuster_OffsetTime_validOffsetIntoOverlap2() {
    // OT has valid offset for resulting time
    OffsetTime ot = OffsetTime.of(2, 30, 30, 40, OFFSET_0200);  // valid offset in overlap
    ZonedDateTime zdt = dateTime(2008, 10, 26, 0, 0, 0, 0, OFFSET_0200, ZONE_PARIS);  // just before overlap
    ZonedDateTime test = zdt.with(ot);
    assertEquals(test.toLocalDateTime(), dateTime(2008, 10, 26, 2, 30, 30, 40));
    assertEquals(test.getOffset(), OFFSET_0200);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:TCKZonedDateTime.java

示例5: test_with_adjuster_LocalDate_retainOffset2

import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void test_with_adjuster_LocalDate_retainOffset2() {
    ZoneId newYork = ZoneId.of("America/New_York");
    LocalDateTime ldt = LocalDateTime.of(2008, 11, 3, 1, 30);
    ZonedDateTime base = ZonedDateTime.of(ldt, newYork);
    assertEquals(base.getOffset(), ZoneOffset.ofHours(-5));
    ZonedDateTime test = base.with(LocalDate.of(2008, 11, 2));
    assertEquals(test.getOffset(), ZoneOffset.ofHours(-5));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:TCKZonedDateTime.java

示例6: test_with_adjuster_Year

import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void test_with_adjuster_Year() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.with(Year.of(2007));
    assertEquals(test, ZonedDateTime.of(ldt.withYear(2007), ZONE_0100));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:TCKZonedDateTime.java

示例7: test_with_adjuster_OffsetDateTime_retainOffsetInOverlap1

import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void test_with_adjuster_OffsetDateTime_retainOffsetInOverlap1() {
    // ODT will be a valid ZDT for the zone, so must be retained exactly
    OffsetDateTime odt = TEST_PARIS_OVERLAP_2008_10_26_02_30.atOffset(OFFSET_0100);
    ZonedDateTime zdt = TEST_LOCAL_2008_06_30_11_30_59_500.atZone(ZONE_PARIS);
    ZonedDateTime test = zdt.with(odt);
    assertEquals(test.toOffsetDateTime(), odt);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:TCKZonedDateTime.java

示例8: test_with_adjuster_OffsetDateTime_validOffsetNotInOverlap

import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void test_with_adjuster_OffsetDateTime_validOffsetNotInOverlap() {
    // ODT will be a valid ZDT for the zone, so must be retained exactly
    OffsetDateTime odt = TEST_LOCAL_2008_06_30_11_30_59_500.atOffset(OFFSET_0200);
    ZonedDateTime zdt = TEST_PARIS_OVERLAP_2008_10_26_02_30.atZone(ZONE_PARIS);
    ZonedDateTime test = zdt.with(odt);
    assertEquals(test.toOffsetDateTime(), odt);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:9,代码来源:TCKZonedDateTime.java

示例9: test_with_adjuster_OffsetDateTime_invalidOffsetIgnored

import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void test_with_adjuster_OffsetDateTime_invalidOffsetIgnored() {
    // ODT has invalid offset for ZDT, so only LDT is set
    OffsetDateTime odt = TEST_LOCAL_2008_06_30_11_30_59_500.atOffset(OFFSET_0130);
    ZonedDateTime zdt = TEST_PARIS_OVERLAP_2008_10_26_02_30.atZone(ZONE_PARIS);
    ZonedDateTime test = zdt.with(odt);
    assertEquals(test.toLocalDateTime(), TEST_LOCAL_2008_06_30_11_30_59_500);
    assertEquals(test.getOffset(), zdt.getOffset());
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:TCKZonedDateTime.java

示例10: test_with_adjuster_OffsetDateTime_retainOffsetInOverlap2

import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void test_with_adjuster_OffsetDateTime_retainOffsetInOverlap2() {
    // ODT will be a valid ZDT for the zone, so must be retained exactly
    OffsetDateTime odt = TEST_PARIS_OVERLAP_2008_10_26_02_30.atOffset(OFFSET_0200);
    ZonedDateTime zdt = TEST_LOCAL_2008_06_30_11_30_59_500.atZone(ZONE_PARIS);
    ZonedDateTime test = zdt.with(odt);
    assertEquals(test.toOffsetDateTime(), odt);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:9,代码来源:TCKZonedDateTime.java

示例11: test_with_adjuster_OffsetTime_validOffsetIntoOverlap1

import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void test_with_adjuster_OffsetTime_validOffsetIntoOverlap1() {
    // OT has valid offset for resulting time
    OffsetTime ot = OffsetTime.of(2, 30, 30, 40, OFFSET_0100);  // valid offset in overlap
    ZonedDateTime zdt = dateTime(2008, 10, 26, 0, 0, 0, 0, OFFSET_0200, ZONE_PARIS);  // just before overlap
    ZonedDateTime test = zdt.with(ot);
    assertEquals(test.toLocalDateTime(), dateTime(2008, 10, 26, 2, 30, 30, 40));
    assertEquals(test.getOffset(), OFFSET_0100);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:TCKZonedDateTime.java

示例12: test_with_adjuster_null

import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test(expectedExceptions=NullPointerException.class)
public void test_with_adjuster_null() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    base.with((TemporalAdjuster) null);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:TCKZonedDateTime.java

示例13: parseConstants

import java.time.ZonedDateTime; //导入方法依赖的package包/类
private static void parseConstants(final char[] chars, final Part[] parts, final long nowEpochMilli) {
    final ZonedDateTime now = ZonedDateTime.ofInstant(Instant.ofEpochMilli(nowEpochMilli), ZoneOffset.UTC);
    final String expression = new String(chars);
    for (final DatePoint datePoint : DatePoint.values()) {
        final String function = datePoint.getFunction();

        int start = expression.indexOf(function, 0);
        while (start != -1) {
            final int end = start + function.length();

            // Obliterate the matched part of the expression so it can't be matched by any other matcher.
            Arrays.fill(chars, start, end, ' ');

            ZonedDateTime time = null;
            switch (datePoint) {
                case NOW:
                    time = now;
                    break;
                case SECOND:
                    time = now.truncatedTo(ChronoUnit.SECONDS);
                    break;
                case MINUTE:
                    time = now.truncatedTo(ChronoUnit.MINUTES);
                    break;
                case HOUR:
                    time = now.truncatedTo(ChronoUnit.HOURS);
                    break;
                case DAY:
                    time = now.truncatedTo(ChronoUnit.DAYS);
                    break;
                case WEEK:
                    TemporalField fieldISO = WeekFields.of(Locale.UK).dayOfWeek();
                    time = now.with(fieldISO, 1); // Monday
                    time = time.truncatedTo(ChronoUnit.DAYS);
                    break;
                case MONTH:
                    time = ZonedDateTime.of(now.getYear(), now.getMonthValue(), 1, 0, 0, 0, 0, now.getZone());
                    break;
                case YEAR:
                    time = ZonedDateTime.of(now.getYear(), 1, 1, 0, 0, 0, 0, now.getZone());
                    break;
            }

            parts[start] = new Part(function, time);

            start = expression.indexOf(function, end);
        }
    }
}
 
开发者ID:gchq,项目名称:stroom-query,代码行数:50,代码来源:DateExpressionParser.java

示例14: test_withMonth_Month_null

import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test(expectedExceptions = NullPointerException.class)
public void test_withMonth_Month_null() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    base.with((Month) null);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:TCKZonedDateTime.java

示例15: test_with_adjuster_LocalTime

import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void test_with_adjuster_LocalTime() {
    ZonedDateTime base = ZonedDateTime.of(TEST_PARIS_OVERLAP_2008_10_26_02_30, ZONE_PARIS);
    ZonedDateTime test = base.with(LocalTime.of(2, 29));
    check(test, 2008, 10, 26, 2, 29, 0, 0, OFFSET_0200, ZONE_PARIS);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:TCKZonedDateTime.java


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