當前位置: 首頁>>代碼示例>>Java>>正文


Java ZonedDateTime.withZoneSameLocal方法代碼示例

本文整理匯總了Java中java.time.ZonedDateTime.withZoneSameLocal方法的典型用法代碼示例。如果您正苦於以下問題:Java ZonedDateTime.withZoneSameLocal方法的具體用法?Java ZonedDateTime.withZoneSameLocal怎麽用?Java ZonedDateTime.withZoneSameLocal使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.time.ZonedDateTime的用法示例。


在下文中一共展示了ZonedDateTime.withZoneSameLocal方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: test_withZoneSameLocal

import java.time.ZonedDateTime; //導入方法依賴的package包/類
@Test
public void test_withZoneSameLocal() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.withZoneSameLocal(ZONE_0200);
    assertEquals(test.toLocalDateTime(), base.toLocalDateTime());
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:8,代碼來源:TCKZonedDateTime.java

示例2: test_withZoneSameLocal_noChange

import java.time.ZonedDateTime; //導入方法依賴的package包/類
@Test
public void test_withZoneSameLocal_noChange() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.withZoneSameLocal(ZONE_0100);
    assertEquals(test, base);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:8,代碼來源:TCKZonedDateTime.java

示例3: test_withZoneSameLocal_retainOffset1

import java.time.ZonedDateTime; //導入方法依賴的package包/類
@Test
public void test_withZoneSameLocal_retainOffset1() {
    LocalDateTime ldt = LocalDateTime.of(2008, 11, 2, 1, 30, 59, 0);  // overlap
    ZonedDateTime base = ZonedDateTime.of(ldt, ZoneId.of("UTC-04:00") );
    ZonedDateTime test = base.withZoneSameLocal(ZoneId.of("America/New_York"));
    assertEquals(base.getOffset(), ZoneOffset.ofHours(-4));
    assertEquals(test.getOffset(), ZoneOffset.ofHours(-4));
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:9,代碼來源:TCKZonedDateTime.java

示例4: test_withZoneSameLocal_retainOffset2

import java.time.ZonedDateTime; //導入方法依賴的package包/類
@Test
public void test_withZoneSameLocal_retainOffset2() {
    LocalDateTime ldt = LocalDateTime.of(2008, 11, 2, 1, 30, 59, 0);  // overlap
    ZonedDateTime base = ZonedDateTime.of(ldt, ZoneId.of("UTC-05:00") );
    ZonedDateTime test = base.withZoneSameLocal(ZoneId.of("America/New_York"));
    assertEquals(base.getOffset(), ZoneOffset.ofHours(-5));
    assertEquals(test.getOffset(), ZoneOffset.ofHours(-5));
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:9,代碼來源:TCKZonedDateTime.java

示例5: test_printText

import java.time.ZonedDateTime; //導入方法依賴的package包/類
public void test_printText() {
    Random r = RandomFactory.getRandom();
    int N = 8;
    Locale[] locales = Locale.getAvailableLocales();
    Set<String> zids = ZoneRulesProvider.getAvailableZoneIds();
    ZonedDateTime zdt = ZonedDateTime.now();

    //System.out.printf("locale==%d, timezone=%d%n", locales.length, zids.size());
    while (N-- > 0) {
        zdt = zdt.withDayOfYear(r.nextInt(365) + 1)
                 .with(ChronoField.SECOND_OF_DAY, r.nextInt(86400));
        for (String zid : zids) {
            if (zid.equals("ROC") || zid.startsWith("Etc/GMT")) {
                continue;      // TBD: match jdk behavior?
            }
            zdt = zdt.withZoneSameLocal(ZoneId.of(zid));
            TimeZone tz = TimeZone.getTimeZone(zid);
            boolean isDST = tz.inDaylightTime(new Date(zdt.toInstant().toEpochMilli()));
            for (Locale locale : locales) {
                String longDisplayName = tz.getDisplayName(isDST, TimeZone.LONG, locale);
                String shortDisplayName = tz.getDisplayName(isDST, TimeZone.SHORT, locale);
                if ((longDisplayName.startsWith("GMT+") && shortDisplayName.startsWith("GMT+"))
                        || (longDisplayName.startsWith("GMT-") && shortDisplayName.startsWith("GMT-"))) {
                    printText(locale, zdt, TextStyle.FULL, tz, tz.getID());
                    printText(locale, zdt, TextStyle.SHORT, tz, tz.getID());
                    continue;
                }
                printText(locale, zdt, TextStyle.FULL, tz,
                        tz.getDisplayName(isDST, TimeZone.LONG, locale));
                printText(locale, zdt, TextStyle.SHORT, tz,
                        tz.getDisplayName(isDST, TimeZone.SHORT, locale));
            }
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:36,代碼來源:TestZoneTextPrinterParser.java

示例6: getTimestamp

import java.time.ZonedDateTime; //導入方法依賴的package包/類
private Timestamp getTimestamp(final String datetimeString) {
    final DateTimeFormatter formatter = DateTimeFormatter.ISO_ZONED_DATE_TIME;
    final ZonedDateTime dateTime = ZonedDateTime.parse(datetimeString.replace(" ", "T").replace(".0", "+00:00"), formatter);
    final ZonedDateTime zonedDateTime = dateTime.withZoneSameLocal(DatumUtil.NL_ZONE_ID);
    return new Timestamp(zonedDateTime.toInstant().toEpochMilli());
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:7,代碼來源:AfnemerindicatieBatchStrategy.java

示例7: test_withZoneSameLocal_null

import java.time.ZonedDateTime; //導入方法依賴的package包/類
@Test(expectedExceptions=NullPointerException.class)
public void test_withZoneSameLocal_null() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    base.withZoneSameLocal(null);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:7,代碼來源:TCKZonedDateTime.java


注:本文中的java.time.ZonedDateTime.withZoneSameLocal方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。