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


Java ZoneOffset.of方法代码示例

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


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

示例1: test_factory_string_invalid

import java.time.ZoneOffset; //导入方法依赖的package包/类
@Test
public void test_factory_string_invalid() {
    String[] values = new String[] {
        "","A","B","C","D","E","F","G","H","I","J","K","L","M",
        "N","O","P","Q","R","S","T","U","V","W","X","Y","ZZ",
        "0", "+0:00","+00:0","+0:0",
        "+000","+00000",
        "+0:00:00","+00:0:00","+00:00:0","+0:0:0","+0:0:00","+00:0:0","+0:00:0",
        "1", "+01_00","+01;00","[email protected]","+01:AA",
        "+19","+19:00","+18:01","+18:00:01","+1801","+180001",
        "-0:00","-00:0","-0:0",
        "-000","-00000",
        "-0:00:00","-00:0:00","-00:00:0","-0:0:0","-0:0:00","-00:0:0","-0:00:0",
        "-19","-19:00","-18:01","-18:00:01","-1801","-180001",
        "-01_00","-01;00","[email protected]","-01:AA",
        "@01:00",
    };
    for (int i = 0; i < values.length; i++) {
        try {
            ZoneOffset.of(values[i]);
            fail("Should have failed:" + values[i]);
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:27,代码来源:TCKZoneOffset.java

示例2: test_factory_string_hours_minutes_noColon

import java.time.ZoneOffset; //导入方法依赖的package包/类
@Test
public void test_factory_string_hours_minutes_noColon() {
    for (int i = -17; i <= 17; i++) {
        for (int j = -59; j <= 59; j++) {
            if ((i < 0 && j <= 0) || (i > 0 && j >= 0) || i == 0) {
                String str = (i < 0 || j < 0 ? "-" : "+") +
                    Integer.toString(Math.abs(i) + 100).substring(1) +
                    Integer.toString(Math.abs(j) + 100).substring(1);
                ZoneOffset test = ZoneOffset.of(str);
                doTestOffset(test, i, j, 0);
            }
        }
    }
    ZoneOffset test1 = ZoneOffset.of("-1800");
    doTestOffset(test1, -18, 0, 0);
    ZoneOffset test2 = ZoneOffset.of("+1800");
    doTestOffset(test2, 18, 0, 0);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:TCKZoneOffset.java

示例3: test_factory_string_hours_minutes_seconds_colon

import java.time.ZoneOffset; //导入方法依赖的package包/类
@Test
public void test_factory_string_hours_minutes_seconds_colon() {
    for (int i = -17; i <= 17; i++) {
        for (int j = -59; j <= 59; j++) {
            for (int k = -59; k <= 59; k++) {
                if ((i < 0 && j <= 0 && k <= 0) || (i > 0 && j >= 0 && k >= 0) ||
                        (i == 0 && ((j < 0 && k <= 0) || (j > 0 && k >= 0) || j == 0))) {
                    String str = (i < 0 || j < 0 || k < 0 ? "-" : "+") +
                        Integer.toString(Math.abs(i) + 100).substring(1) + ":" +
                        Integer.toString(Math.abs(j) + 100).substring(1) + ":" +
                        Integer.toString(Math.abs(k) + 100).substring(1);
                    ZoneOffset test = ZoneOffset.of(str);
                    doTestOffset(test, i, j, k);
                }
            }
        }
    }
    ZoneOffset test1 = ZoneOffset.of("-18:00:00");
    doTestOffset(test1, -18, 0, 0);
    ZoneOffset test2 = ZoneOffset.of("+18:00:00");
    doTestOffset(test2, 18, 0, 0);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:TCKZoneOffset.java

示例4: test_factory_string_hours_minutes_seconds_noColon

import java.time.ZoneOffset; //导入方法依赖的package包/类
@Test
public void test_factory_string_hours_minutes_seconds_noColon() {
    for (int i = -17; i <= 17; i++) {
        for (int j = -59; j <= 59; j++) {
            for (int k = -59; k <= 59; k++) {
                if ((i < 0 && j <= 0 && k <= 0) || (i > 0 && j >= 0 && k >= 0) ||
                        (i == 0 && ((j < 0 && k <= 0) || (j > 0 && k >= 0) || j == 0))) {
                    String str = (i < 0 || j < 0 || k < 0 ? "-" : "+") +
                        Integer.toString(Math.abs(i) + 100).substring(1) +
                        Integer.toString(Math.abs(j) + 100).substring(1) +
                        Integer.toString(Math.abs(k) + 100).substring(1);
                    ZoneOffset test = ZoneOffset.of(str);
                    doTestOffset(test, i, j, k);
                }
            }
        }
    }
    ZoneOffset test1 = ZoneOffset.of("-180000");
    doTestOffset(test1, -18, 0, 0);
    ZoneOffset test2 = ZoneOffset.of("+180000");
    doTestOffset(test2, 18, 0, 0);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:TCKZoneOffset.java

示例5: test_factory_string_hours_minutes_colon

import java.time.ZoneOffset; //导入方法依赖的package包/类
@Test
public void test_factory_string_hours_minutes_colon() {
    for (int i = -17; i <= 17; i++) {
        for (int j = -59; j <= 59; j++) {
            if ((i < 0 && j <= 0) || (i > 0 && j >= 0) || i == 0) {
                String str = (i < 0 || j < 0 ? "-" : "+") +
                    Integer.toString(Math.abs(i) + 100).substring(1) + ":" +
                    Integer.toString(Math.abs(j) + 100).substring(1);
                ZoneOffset test = ZoneOffset.of(str);
                doTestOffset(test, i, j, 0);
            }
        }
    }
    ZoneOffset test1 = ZoneOffset.of("-18:00");
    doTestOffset(test1, -18, 0, 0);
    ZoneOffset test2 = ZoneOffset.of("+18:00");
    doTestOffset(test2, 18, 0, 0);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:TCKZoneOffset.java

示例6: test_prefixOfOffset

import java.time.ZoneOffset; //导入方法依赖的package包/类
@Test(dataProvider="prefixValid")
public void test_prefixOfOffset(String prefix, String offset) {
    ZoneOffset zoff = ZoneOffset.of(offset);
    ZoneId zoneId = ZoneId.ofOffset(prefix, zoff);
    assertEquals(zoneId.getId(), prefix + zoff.getId(), "in correct id for : " + prefix + ", zoff: " + zoff);

}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:TCKZoneId.java

示例7: test_factory_string_UTC

import java.time.ZoneOffset; //导入方法依赖的package包/类
@Test
public void test_factory_string_UTC() {
    String[] values = new String[] {
        "Z", "+0",
        "+00","+0000","+00:00","+000000","+00:00:00",
        "-00","-0000","-00:00","-000000","-00:00:00",
    };
    for (int i = 0; i < values.length; i++) {
        ZoneOffset test = ZoneOffset.of(values[i]);
        assertSame(test, ZoneOffset.UTC);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:13,代码来源:TCKZoneOffset.java

示例8: test_factory_string_singleDigitHours

import java.time.ZoneOffset; //导入方法依赖的package包/类
@Test
public void test_factory_string_singleDigitHours() {
    for (int i = -9; i <= 9; i++) {
        String str = (i < 0 ? "-" : "+") + Math.abs(i);
        ZoneOffset test = ZoneOffset.of(str);
        doTestOffset(test, i, 0, 0);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:9,代码来源:TCKZoneOffset.java

示例9: test_factory_string_hours

import java.time.ZoneOffset; //导入方法依赖的package包/类
@Test
public void test_factory_string_hours() {
    for (int i = -18; i <= 18; i++) {
        String str = (i < 0 ? "-" : "+") + Integer.toString(Math.abs(i) + 100).substring(1);
        ZoneOffset test = ZoneOffset.of(str);
        doTestOffset(test, i, 0, 0);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:9,代码来源:TCKZoneOffset.java

示例10: test_NewYork_preTimeZones

import java.time.ZoneOffset; //导入方法依赖的package包/类
public void test_NewYork_preTimeZones() {
    ZoneRules test = americaNewYork();
    ZonedDateTime old = createZDT(1800, 1, 1, ZoneOffset.UTC);
    Instant instant = old.toInstant();
    ZoneOffset offset = ZoneOffset.of("-04:56:02");
    assertEquals(test.getOffset(instant), offset);
    checkOffset(test, old.toLocalDateTime(), offset, 1);
    assertEquals(test.getStandardOffset(instant), offset);
    assertEquals(test.getDaylightSavings(instant), Duration.ZERO);
    assertEquals(test.isDaylightSavings(instant), false);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:TCKZoneRules.java

示例11: test_invalidPrefixOfOffset

import java.time.ZoneOffset; //导入方法依赖的package包/类
@Test(dataProvider="prefixInvalid", expectedExceptions=java.lang.IllegalArgumentException.class)
public void test_invalidPrefixOfOffset(String prefix, String offset) {
    ZoneOffset zoff = ZoneOffset.of(offset);
    ZoneId zoneId = ZoneId.ofOffset(prefix, zoff);
    fail("should have thrown an exception for prefix: " + prefix);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:7,代码来源:TCKZoneId.java

示例12: test_factory_string_null

import java.time.ZoneOffset; //导入方法依赖的package包/类
@Test(expectedExceptions=NullPointerException.class)
public void test_factory_string_null() {
    ZoneOffset.of((String) null);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:5,代码来源:TCKZoneOffset.java

示例13: today

import java.time.ZoneOffset; //导入方法依赖的package包/类
private String today() {
    ZoneOffset stockholmOffset = ZoneOffset.of("+02:00");
    DateTimeFormatter httpDateFormat = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy");
    return LocalDate.now(stockholmOffset).format(httpDateFormat);
}
 
开发者ID:andreschaffer,项目名称:http-caching-and-concurrency-examples,代码行数:6,代码来源:DaylightIT.java


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