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


Java LocalDateTime.atZone方法代码示例

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


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

示例1: isRecentJoin

import java.time.LocalDateTime; //导入方法依赖的package包/类
private boolean isRecentJoin(UgcPlayer.Membership team) {
    if (team.getJoinedTeam() == null || !"true".equals(team.getActive())) {
        return false;
    }
    LocalDateTime date = LocalDateTime.parse(team.getJoinedTeam(), DateTimeFormatter.ofPattern(UGC_NEW_DATE_FORMAT, Locale.ENGLISH));
    ZonedDateTime join = date.atZone(UGC_ZONE_ID);
    return ZonedDateTime.now().minusHours(18).isBefore(join);
}
 
开发者ID:quanticc,项目名称:sentry,代码行数:9,代码来源:Roster.java

示例2: test_print

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(dataProvider="print")
public void test_print(String offsetPattern, String noOffset, LocalDateTime ldt, ZoneId zone, String expected) {
    ZonedDateTime zdt = ldt.atZone(zone);
    builder.appendOffset(offsetPattern, noOffset);
    String output = builder.toFormatter().format(zdt);
    assertEquals(output, expected);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:TCKOffsetPrinterParser.java

示例3: test_print_localized

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(dataProvider="print_localized")
public void test_print_localized(TextStyle style, LocalDateTime ldt, ZoneOffset offset, String expected) {
    OffsetDateTime odt = OffsetDateTime.of(ldt, offset);
    ZonedDateTime zdt = ldt.atZone(offset);

    DateTimeFormatter f = new DateTimeFormatterBuilder().appendLocalizedOffset(style)
                                                        .toFormatter();
    assertEquals(f.format(odt), expected);
    assertEquals(f.format(zdt), expected);
    assertEquals(f.parse(expected, ZoneOffset::from), offset);

    if (style == TextStyle.FULL) {
        f = new DateTimeFormatterBuilder().appendPattern("ZZZZ")
                                          .toFormatter();
        assertEquals(f.format(odt), expected);
        assertEquals(f.format(zdt), expected);
        assertEquals(f.parse(expected, ZoneOffset::from), offset);

        f = new DateTimeFormatterBuilder().appendPattern("OOOO")
                                          .toFormatter();
        assertEquals(f.format(odt), expected);
        assertEquals(f.format(zdt), expected);
        assertEquals(f.parse(expected, ZoneOffset::from), offset);
    }

    if (style == TextStyle.SHORT) {
        f = new DateTimeFormatterBuilder().appendPattern("O")
                                          .toFormatter();
        assertEquals(f.format(odt), expected);
        assertEquals(f.format(zdt), expected);
        assertEquals(f.parse(expected, ZoneOffset::from), offset);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:TCKOffsetPrinterParser.java

示例4: test_toInstant_UTC

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(dataProvider="toInstant")
public void test_toInstant_UTC(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
    ZonedDateTime dt = ldt.atZone(ZoneOffset.UTC);
    Instant test = dt.toInstant();
    assertEquals(test.getEpochSecond(), expectedEpSec);
    assertEquals(test.getNano(), expectedNos);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:TCKZonedDateTime.java

示例5: test_print

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(dataProvider="print")
public void test_print(LocalDateTime ldt, ZoneId zone, String expected) {
    ZonedDateTime zdt = ldt.atZone(zone);
    builder.appendZoneId();
    String output = builder.toFormatter().format(zdt);
    assertEquals(output, expected);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:TCKZoneIdPrinterParser.java

示例6: test_print_pattern_VV

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(dataProvider="print")
public void test_print_pattern_VV(LocalDateTime ldt, ZoneId zone, String expected) {
    ZonedDateTime zdt = ldt.atZone(zone);
    builder.appendPattern("VV");
    String output = builder.toFormatter().format(zdt);
    assertEquals(output, expected);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:TCKZoneIdPrinterParser.java

示例7: test_print_pattern_x

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(dataProvider="print")
public void test_print_pattern_x(String offsetPattern, String noOffset, LocalDateTime ldt, ZoneId zone, String expected) {
    String pattern = null;
    String zero = null;
    if (offsetPattern.equals("+HHmm") && noOffset.equals("Z")) {
        pattern = "x";
        zero = "+00";
    } else if (offsetPattern.equals("+HHMM") && noOffset.equals("Z")) {
        pattern = "xx";
        zero = "+0000";
    } else if (offsetPattern.equals("+HH:MM") && noOffset.equals("Z")) {
        pattern = "xxx";
        zero = "+00:00";
    } else if (offsetPattern.equals("+HHMMss") && noOffset.equals("Z")) {
        pattern = "xxxx";
        zero = "+0000";
    } else if (offsetPattern.equals("+HH:MM:ss") && noOffset.equals("Z")) {
        pattern = "xxxxx";
        zero = "+00:00";
    }
    if (pattern != null) {
        ZonedDateTime zdt = ldt.atZone(zone);
        builder.appendPattern(pattern);
        String output = builder.toFormatter().format(zdt);
        assertEquals(output, (expected.equals("Z") ? zero : expected));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:TCKOffsetPrinterParser.java

示例8: test_toInstant_P0100

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(dataProvider="toInstant")
public void test_toInstant_P0100(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
    ZonedDateTime dt = ldt.atZone(ZONE_0100);
    Instant test = dt.toInstant();
    assertEquals(test.getEpochSecond(), expectedEpSec - 3600);
    assertEquals(test.getNano(), expectedNos);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:TCKZonedDateTime.java

示例9: test_toInstant_M0100

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(dataProvider="toInstant")
public void test_toInstant_M0100(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
    ZonedDateTime dt = ldt.atZone(ZONE_M0100);
    Instant test = dt.toInstant();
    assertEquals(test.getEpochSecond(), expectedEpSec + 3600);
    assertEquals(test.getNano(), expectedNos);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:TCKZonedDateTime.java

示例10: test_toEpochSecond_UTC

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(dataProvider="toInstant")
public void test_toEpochSecond_UTC(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
    ZonedDateTime dt = ldt.atZone(ZoneOffset.UTC);
    assertEquals(dt.toEpochSecond(), expectedEpSec);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:TCKZonedDateTime.java

示例11: test_toEpochSecond_P0100

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(dataProvider="toInstant")
public void test_toEpochSecond_P0100(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
    ZonedDateTime dt = ldt.atZone(ZONE_0100);
    assertEquals(dt.toEpochSecond(), expectedEpSec - 3600);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:TCKZonedDateTime.java

示例12: test_atZone_nullTimeZone

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(expectedExceptions=NullPointerException.class)
public void test_atZone_nullTimeZone() {
    LocalDateTime t = LocalDateTime.of(2008, 6, 30, 11, 30);
    t.atZone((ZoneId) null);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:TCKLocalDateTime.java

示例13: test_toEpochSecond_M0100

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(dataProvider="toInstant")
public void test_toEpochSecond_M0100(LocalDateTime ldt, long expectedEpSec, int expectedNos) {
    ZonedDateTime dt = ldt.atZone(ZONE_M0100);
    assertEquals(dt.toEpochSecond(), expectedEpSec + 3600);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:TCKZonedDateTime.java


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