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