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


Java ZoneId.of方法代碼示例

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


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

示例1: testLowerDateAccess

import java.time.ZoneId; //導入方法依賴的package包/類
@Test()
public void testLowerDateAccess() {
    final ZoneId gmt = ZoneId.of("GMT");
    final Index<ZonedDateTime> dates = Index.of(Arrays.asList(
            ZonedDateTime.of(2014, 5, 2, 9, 30, 0, 0, gmt),
            ZonedDateTime.of(2014, 5, 2, 10, 30, 0, 0, gmt),
            ZonedDateTime.of(2014, 5, 2, 11, 30, 0, 0, gmt),
            ZonedDateTime.of(2014, 5, 2, 12, 30, 0, 0, gmt),
            ZonedDateTime.of(2014, 5, 2, 13, 30, 0, 0, gmt),
            ZonedDateTime.of(2014, 5, 2, 14, 30, 0, 0, gmt),
            ZonedDateTime.of(2014, 5, 2, 15, 30, 0, 0, gmt),
            ZonedDateTime.of(2014, 5, 2, 16, 30, 0, 0, gmt)
    ));
    final DataFrame<ZonedDateTime,ZonedDateTime> frame1 = DataFrame.ofDoubles(dates, dates);
    final DataFrame<ZonedDateTime,ZonedDateTime> frame2 = frame1.select(r -> true, c -> true);
    Stream.of(frame1, frame2).forEach(frame -> {
        frame1.applyDoubles(value -> Math.random());
        Assert.assertTrue(frame.rows().lowerKey(dates.getKey(3)).isPresent());
        Assert.assertTrue(frame.cols().lowerKey(dates.getKey(3)).isPresent());
        Assert.assertEquals(frame.rows().lowerKey(dates.getKey(3)).get(), dates.getKey(2));
        Assert.assertEquals(frame.cols().lowerKey(dates.getKey(6)).get(), dates.getKey(5));
        Assert.assertTrue(!frame.rows().lowerKey(dates.getKey(0).minusDays(1)).isPresent());
        Assert.assertTrue(!frame.cols().lowerKey(dates.getKey(0).minusDays(1)).isPresent());
    });
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:26,代碼來源:DimensionTests.java

示例2: toZoneId0

import java.time.ZoneId; //導入方法依賴的package包/類
private ZoneId toZoneId0() {
    String id = getID();
    TimeZone defaultZone = defaultTimeZone;
    // are we not defaultTimeZone but our id is equal to default's?
    if (defaultZone != this &&
        defaultZone != null && id.equals(defaultZone.getID())) {
        // delegate to default TZ which is effectively immutable
        return defaultZone.toZoneId();
    }
    // derive it ourselves
    if (ZoneInfoFile.useOldMapping() && id.length() == 3) {
        if ("EST".equals(id))
            return ZoneId.of("America/New_York");
        if ("MST".equals(id))
            return ZoneId.of("America/Denver");
        if ("HST".equals(id))
            return ZoneId.of("America/Honolulu");
    }
    return ZoneId.of(id, ZoneId.SHORT_IDS);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:TimeZone.java

示例3: testZonedDateTime

import java.time.ZoneId; //導入方法依賴的package包/類
@Test()
public void testZonedDateTime() {
    final int count = 10;
    final Random random = new Random();
    final Array<ZonedDateTime> array1 = Array.map(ZonedDateTime.class, count, null);
    final ZonedDateTime[] array2 = new ZonedDateTime[count];
    for (int i=0; i<count; ++i) {
        final ZoneId zoneId = i % 2 == 0 ? ZoneId.of("UTC") : ZoneId.systemDefault();
        final ZonedDateTime value = ZonedDateTime.now().minusMinutes(random.nextInt(100)).withZoneSameInstant(zoneId);
        array1.setValue(i, value);
        array2[i] = value;
    }
    for (int i=0; i<count; ++i) {
        final ZonedDateTime v1 = array1.getValue(i);
        final ZonedDateTime v2 = array2[i];
        Assert.assertEquals(v1, v2);
        System.out.println(v1);
    }
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:20,代碼來源:ArrayMappedTests.java

示例4: test_dateNow

import java.time.ZoneId; //導入方法依賴的package包/類
@Test
public void test_dateNow(){
    assertEquals(MinguoChronology.INSTANCE.dateNow(), MinguoDate.now()) ;
    assertEquals(MinguoChronology.INSTANCE.dateNow(), MinguoDate.now(ZoneId.systemDefault())) ;
    assertEquals(MinguoChronology.INSTANCE.dateNow(), MinguoDate.now(Clock.systemDefaultZone())) ;
    assertEquals(MinguoChronology.INSTANCE.dateNow(), MinguoDate.now(Clock.systemDefaultZone().getZone())) ;

    assertEquals(MinguoChronology.INSTANCE.dateNow(), MinguoChronology.INSTANCE.dateNow(ZoneId.systemDefault())) ;
    assertEquals(MinguoChronology.INSTANCE.dateNow(), MinguoChronology.INSTANCE.dateNow(Clock.systemDefaultZone())) ;
    assertEquals(MinguoChronology.INSTANCE.dateNow(), MinguoChronology.INSTANCE.dateNow(Clock.systemDefaultZone().getZone())) ;

    ZoneId zoneId = ZoneId.of("Europe/Paris");
    assertEquals(MinguoChronology.INSTANCE.dateNow(zoneId), MinguoChronology.INSTANCE.dateNow(Clock.system(zoneId))) ;
    assertEquals(MinguoChronology.INSTANCE.dateNow(zoneId), MinguoChronology.INSTANCE.dateNow(Clock.system(zoneId).getZone())) ;
    assertEquals(MinguoChronology.INSTANCE.dateNow(zoneId), MinguoDate.now(Clock.system(zoneId))) ;
    assertEquals(MinguoChronology.INSTANCE.dateNow(zoneId), MinguoDate.now(Clock.system(zoneId).getZone())) ;

    assertEquals(MinguoChronology.INSTANCE.dateNow(ZoneId.of(ZoneOffset.UTC.getId())), MinguoChronology.INSTANCE.dateNow(Clock.systemUTC())) ;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:20,代碼來源:TCKMinguoChronology.java

示例5: test_IsoChronology_dateNow

import java.time.ZoneId; //導入方法依賴的package包/類
@Test
public void test_IsoChronology_dateNow() {
    ZoneId zoneId_paris = ZoneId.of("Europe/Paris");
    Clock clock = Clock.system(zoneId_paris);

    Chronology chrono = Chronology.of("ISO");
    assertEquals(chrono.dateNow(), IsoChronology.INSTANCE.dateNow());
    assertEquals(chrono.dateNow(zoneId_paris), IsoChronology.INSTANCE.dateNow(zoneId_paris));
    assertEquals(chrono.dateNow(clock), IsoChronology.INSTANCE.dateNow(clock));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:11,代碼來源:TCKChronology.java

示例6: test_MinguoChronology_dateNow

import java.time.ZoneId; //導入方法依賴的package包/類
@Test
public void test_MinguoChronology_dateNow() {
    ZoneId zoneId_paris = ZoneId.of("Europe/Paris");
    Clock clock = Clock.system(zoneId_paris);

    Chronology chrono = Chronology.of("Minguo");
    assertEquals(chrono.dateNow(), MinguoChronology.INSTANCE.dateNow());
    assertEquals(chrono.dateNow(zoneId_paris), MinguoChronology.INSTANCE.dateNow(zoneId_paris));
    assertEquals(chrono.dateNow(clock), MinguoChronology.INSTANCE.dateNow(clock));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:11,代碼來源:TCKChronology.java

示例7: test_London_getOffsetInfo_fromDST

import java.time.ZoneId; //導入方法依賴的package包/類
public void test_London_getOffsetInfo_fromDST() {
    ZoneId test = ZoneId.of("Europe/London");
    checkOffset(test.getRules(), createLDT(2008, 10, 24), ZoneOffset.ofHours(1), 1);
    checkOffset(test.getRules(), createLDT(2008, 10, 25), ZoneOffset.ofHours(1), 1);
    checkOffset(test.getRules(), createLDT(2008, 10, 26), ZoneOffset.ofHours(1), 1);
    checkOffset(test.getRules(), createLDT(2008, 10, 27), ZoneOffset.ofHours(0), 1);
    checkOffset(test.getRules(), createLDT(2008, 10, 28), ZoneOffset.ofHours(0), 1);
    checkOffset(test.getRules(), createLDT(2008, 10, 29), ZoneOffset.ofHours(0), 1);
    checkOffset(test.getRules(), createLDT(2008, 10, 30), ZoneOffset.ofHours(0), 1);
    checkOffset(test.getRules(), createLDT(2008, 10, 31), ZoneOffset.ofHours(0), 1);
    // cutover at 01:00Z
    checkOffset(test.getRules(), LocalDateTime.of(2008, 10, 26, 0, 59, 59, 999999999), ZoneOffset.ofHours(1), 1);
    checkOffset(test.getRules(), LocalDateTime.of(2008, 10, 26, 1, 30, 0, 0), ZoneOffset.ofHours(1), OVERLAP);
    checkOffset(test.getRules(), LocalDateTime.of(2008, 10, 26, 2, 0, 0, 0), ZoneOffset.ofHours(0), 1);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:TestZoneId.java

示例8: test_NewYork_getOffset

import java.time.ZoneId; //導入方法依賴的package包/類
public void test_NewYork_getOffset() {
    ZoneId test = ZoneId.of("America/New_York");
    ZoneOffset offset = ZoneOffset.ofHours(-5);
    assertEquals(test.getRules().getOffset(createInstant(2008, 1, 1, offset)), ZoneOffset.ofHours(-5));
    assertEquals(test.getRules().getOffset(createInstant(2008, 2, 1, offset)), ZoneOffset.ofHours(-5));
    assertEquals(test.getRules().getOffset(createInstant(2008, 3, 1, offset)), ZoneOffset.ofHours(-5));
    assertEquals(test.getRules().getOffset(createInstant(2008, 4, 1, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getRules().getOffset(createInstant(2008, 5, 1, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getRules().getOffset(createInstant(2008, 6, 1, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getRules().getOffset(createInstant(2008, 7, 1, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getRules().getOffset(createInstant(2008, 8, 1, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getRules().getOffset(createInstant(2008, 9, 1, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getRules().getOffset(createInstant(2008, 10, 1, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getRules().getOffset(createInstant(2008, 11, 1, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getRules().getOffset(createInstant(2008, 12, 1, offset)), ZoneOffset.ofHours(-5));
    assertEquals(test.getRules().getOffset(createInstant(2008, 1, 28, offset)), ZoneOffset.ofHours(-5));
    assertEquals(test.getRules().getOffset(createInstant(2008, 2, 28, offset)), ZoneOffset.ofHours(-5));
    assertEquals(test.getRules().getOffset(createInstant(2008, 3, 28, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getRules().getOffset(createInstant(2008, 4, 28, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getRules().getOffset(createInstant(2008, 5, 28, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getRules().getOffset(createInstant(2008, 6, 28, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getRules().getOffset(createInstant(2008, 7, 28, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getRules().getOffset(createInstant(2008, 8, 28, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getRules().getOffset(createInstant(2008, 9, 28, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getRules().getOffset(createInstant(2008, 10, 28, offset)), ZoneOffset.ofHours(-4));
    assertEquals(test.getRules().getOffset(createInstant(2008, 11, 28, offset)), ZoneOffset.ofHours(-5));
    assertEquals(test.getRules().getOffset(createInstant(2008, 12, 28, offset)), ZoneOffset.ofHours(-5));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:29,代碼來源:TestZoneId.java

示例9: parseZone

import java.time.ZoneId; //導入方法依賴的package包/類
/**
 * Parses user supplied input for zone information
 * Allows for zone names to be inputted without proper capitalization
 * @param userInput (String) user input
 * @return (ZoneId) zone information as parsed
 */
public static ZoneId parseZone(String userInput)
{
    for(String validZone : ZoneId.getAvailableZoneIds())
    {
        if(validZone.equalsIgnoreCase(userInput))
        {
            return ZoneId.of(validZone);
        }
    }
    return ZoneId.of(Main.getBotSettingsManager().getTimeZone());
}
 
開發者ID:notem,項目名稱:Saber-Bot,代碼行數:18,代碼來源:ParsingUtilities.java

示例10: buildCalendrical

import java.time.ZoneId; //導入方法依賴的package包/類
private void buildCalendrical(Expected expected, String offsetId, String zoneId) {
    if (offsetId != null) {
        expected.add(ZoneOffset.of(offsetId));
    }
    if (zoneId != null) {
        expected.zone = ZoneId.of(zoneId);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:9,代碼來源:TCKDateTimeFormatters.java

示例11: factory_of_String_offsetBasedInvalid_prefixGMT

import java.time.ZoneId; //導入方法依賴的package包/類
@Test(dataProvider="offsetBasedInvalid", expectedExceptions=DateTimeException.class)
public void factory_of_String_offsetBasedInvalid_prefixGMT(String id) {
    if (id.equals("0")) {
        throw new DateTimeException("Fake exception: GMT0 is valid, not invalid");
    }
    ZoneId.of("GMT" + id);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:TCKZoneId.java

示例12: toZoneId

import java.time.ZoneId; //導入方法依賴的package包/類
/**
 * Converts this {@code TimeZone} object to a {@code ZoneId}.
 *
 * @return a {@code ZoneId} representing the same time zone as this
 *         {@code TimeZone}
 * @since 1.8
 */
public ZoneId toZoneId() {
    String id = getID();
    if (ZoneInfoFile.useOldMapping() && id.length() == 3) {
        if ("EST".equals(id))
            return ZoneId.of("America/New_York");
        if ("MST".equals(id))
            return ZoneId.of("America/Denver");
        if ("HST".equals(id))
            return ZoneId.of("America/Honolulu");
    }
    return ZoneId.of(id, ZoneId.SHORT_IDS);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:20,代碼來源:TimeZone.java

示例13: test_Paris_getOffset_fromDST

import java.time.ZoneId; //導入方法依賴的package包/類
public void test_Paris_getOffset_fromDST() {
    ZoneId test = ZoneId.of("Europe/Paris");
    assertEquals(test.getRules().getOffset(createInstant(2008, 10, 24, ZoneOffset.UTC)), ZoneOffset.ofHours(2));
    assertEquals(test.getRules().getOffset(createInstant(2008, 10, 25, ZoneOffset.UTC)), ZoneOffset.ofHours(2));
    assertEquals(test.getRules().getOffset(createInstant(2008, 10, 26, ZoneOffset.UTC)), ZoneOffset.ofHours(2));
    assertEquals(test.getRules().getOffset(createInstant(2008, 10, 27, ZoneOffset.UTC)), ZoneOffset.ofHours(1));
    assertEquals(test.getRules().getOffset(createInstant(2008, 10, 28, ZoneOffset.UTC)), ZoneOffset.ofHours(1));
    assertEquals(test.getRules().getOffset(createInstant(2008, 10, 29, ZoneOffset.UTC)), ZoneOffset.ofHours(1));
    assertEquals(test.getRules().getOffset(createInstant(2008, 10, 30, ZoneOffset.UTC)), ZoneOffset.ofHours(1));
    assertEquals(test.getRules().getOffset(createInstant(2008, 10, 31, ZoneOffset.UTC)), ZoneOffset.ofHours(1));
    // cutover at 01:00Z
    assertEquals(test.getRules().getOffset(createInstant(2008, 10, 26, 0, 59, 59, 999999999, ZoneOffset.UTC)), ZoneOffset.ofHours(2));
    assertEquals(test.getRules().getOffset(createInstant(2008, 10, 26, 1, 0, 0, 0, ZoneOffset.UTC)), ZoneOffset.ofHours(1));
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:15,代碼來源:TestZoneId.java

示例14: now_ZoneId

import java.time.ZoneId; //導入方法依賴的package包/類
@Test
public void now_ZoneId() {
    ZoneId zone = ZoneId.of("UTC+01:02:03");
    LocalTime expected = LocalTime.now(Clock.system(zone));
    LocalTime test = LocalTime.now(zone);
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = LocalTime.now(Clock.system(zone));
        test = LocalTime.now(zone);
    }
    assertEquals(test, expected);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:15,代碼來源:TCKLocalTime.java

示例15: test_ThaiBuddhistChronology_dateNow

import java.time.ZoneId; //導入方法依賴的package包/類
@Test
public void test_ThaiBuddhistChronology_dateNow() {
    ZoneId zoneId_paris = ZoneId.of("Europe/Paris");
    Clock clock = Clock.system(zoneId_paris);

    Chronology chrono = Chronology.of("ThaiBuddhist");
    assertEquals(chrono.dateNow(), ThaiBuddhistChronology.INSTANCE.dateNow());
    assertEquals(chrono.dateNow(zoneId_paris), ThaiBuddhistChronology.INSTANCE.dateNow(zoneId_paris));
    assertEquals(chrono.dateNow(clock), ThaiBuddhistChronology.INSTANCE.dateNow(clock));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:11,代碼來源:TCKChronology.java


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