當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。