当前位置: 首页>>代码示例>>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;未经允许,请勿转载。