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


Java ZoneOffset.ofHoursMinutes方法代码示例

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


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

示例1: create

import java.time.ZoneOffset; //导入方法依赖的package包/类
public static DateTimeFormatter create(final DateTimeFormat dateTimeFormat, final String dateTimeLocale) {
    java.time.format.DateTimeFormatter format = null;
    ZoneId zone = ZoneOffset.UTC;

    if (dateTimeFormat != null) {
        String pattern = dateTimeFormat.getPattern();
        if (pattern != null && pattern.trim().length() > 0) {
            final TimeZone timeZone = dateTimeFormat.getTimeZone();

            if (timeZone != null) {
                if (TimeZone.Use.UTC.equals(timeZone.getUse())) {
                    zone = ZoneOffset.UTC;
                } else if (TimeZone.Use.LOCAL.equals(timeZone.getUse())) {
                    zone = ZoneId.systemDefault();

                    try {
                        if (dateTimeLocale != null) {
                            zone = ZoneId.of(dateTimeLocale);
                        }
                    } catch (final IllegalArgumentException e) {
                        // The client time zone was not recognised so we'll
                        // use the default.
                    }

                } else if (TimeZone.Use.ID.equals(timeZone.getUse())) {
                    zone = ZoneId.of(timeZone.getId());
                } else if (TimeZone.Use.OFFSET.equals(timeZone.getUse())) {
                    zone = ZoneOffset.ofHoursMinutes(getInt(timeZone.getOffsetHours()),
                            getInt(timeZone.getOffsetMinutes()));
                }
            }

            format = java.time.format.DateTimeFormatter.ofPattern(pattern);
        }
    }

    return new DateTimeFormatter(format, zone);
}
 
开发者ID:gchq,项目名称:stroom-query,代码行数:39,代码来源:DateTimeFormatter.java

示例2: test_factory_int_hours_minutes

import java.time.ZoneOffset; //导入方法依赖的package包/类
@Test
public void test_factory_int_hours_minutes() {
    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) {
                ZoneOffset test = ZoneOffset.ofHoursMinutes(i, j);
                doTestOffset(test, i, j, 0);
            }
        }
    }
    ZoneOffset test1 = ZoneOffset.ofHoursMinutes(-18, 0);
    doTestOffset(test1, -18, 0, 0);
    ZoneOffset test2 = ZoneOffset.ofHoursMinutes(18, 0);
    doTestOffset(test2, 18, 0, 0);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:TCKZoneOffset.java

示例3: data_parseSuccess

import java.time.ZoneOffset; //导入方法依赖的package包/类
@DataProvider(name="parseSuccess")
Object[][] data_parseSuccess() {
    return new Object[][] {
            {"Z", 1, -1, ZoneId.of("Z")},
            {"UTC", 3, -1, ZoneId.of("UTC")},
            {"UT", 2, -1, ZoneId.of("UT")},
            {"GMT", 3, -1, ZoneId.of("GMT")},

            {"+00:00", 6, -1, ZoneOffset.UTC},
            {"UTC+00:00", 9, -1, ZoneId.of("UTC")},
            {"UT+00:00", 8, -1, ZoneId.of("UT")},
            {"GMT+00:00", 9, -1, ZoneId.of("GMT")},
            {"-00:00", 6, -1, ZoneOffset.UTC},
            {"UTC-00:00", 9, -1, ZoneId.of("UTC")},
            {"UT-00:00", 8, -1, ZoneId.of("UT")},
            {"GMT-00:00", 9, -1, ZoneId.of("GMT")},

            {"+01:30", 6, -1, ZoneOffset.ofHoursMinutes(1, 30)},
            {"UTC+01:30", 9, -1, ZoneId.of("UTC+01:30")},
            {"UT+02:30", 8, -1, ZoneId.of("UT+02:30")},
            {"GMT+03:30", 9, -1, ZoneId.of("GMT+03:30")},
            {"-01:30", 6, -1, ZoneOffset.ofHoursMinutes(-1, -30)},
            {"UTC-01:30", 9, -1, ZoneId.of("UTC-01:30")},
            {"UT-02:30", 8, -1, ZoneId.of("UT-02:30")},
            {"GMT-03:30", 9, -1, ZoneId.of("GMT-03:30")},

            // fallback to UTC
            {"UTC-01:WW", 3, -1, ZoneId.of("UTC")},
            {"UT-02:WW", 2, -1, ZoneId.of("UT")},
            {"GMT-03:WW", 3, -1, ZoneId.of("GMT")},
            {"Z0", 1, -1, ZoneOffset.UTC},
            {"UTC1", 3, -1, ZoneId.of("UTC")},

            // Z not parsed as zero
            {"UTCZ", 3, -1, ZoneId.of("UTC")},
            {"UTZ", 2, -1, ZoneId.of("UT")},
            {"GMTZ", 3, -1, ZoneId.of("GMT")},

            // 0 not parsed
            {"UTC0", 3, -1, ZoneId.of("UTC")},
            {"UT0", 2, -1, ZoneId.of("UT")},

            // fail to parse
            {"", 0, 0, null},
            {"A", 0, 0, null},
            {"UZ", 0, 0, null},
            {"GMA", 0, 0, null},
            {"0", 0, 0, null},
            {"+", 0, 0, null},
            {"-", 0, 0, null},

            // zone IDs
            {"Europe/London", 13, -1, ZoneId.of("Europe/London")},
            {"America/New_York", 16, -1, ZoneId.of("America/New_York")},
            {"America/Bogusville", 0, 0, null},
    };
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:58,代码来源:TCKZoneIdPrinterParser.java

示例4: test_factory_int_hours_minutes_tooBig

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

示例5: test_factory_int_hours_minutes_tooSmall

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

示例6: provider_offsets

import java.time.ZoneOffset; //导入方法依赖的package包/类
@DataProvider(name="offsets")
Object[][] provider_offsets() {
    return new Object[][] {
        {"+HH", "+00", ZoneOffset.UTC},
        {"+HH", "-00", ZoneOffset.UTC},
        {"+HH", "+01", ZoneOffset.ofHours(1)},
        {"+HH", "-01", ZoneOffset.ofHours(-1)},

        {"+HHMM", "+0000", ZoneOffset.UTC},
        {"+HHMM", "-0000", ZoneOffset.UTC},
        {"+HHMM", "+0102", ZoneOffset.ofHoursMinutes(1, 2)},
        {"+HHMM", "-0102", ZoneOffset.ofHoursMinutes(-1, -2)},

        {"+HH:MM", "+00:00", ZoneOffset.UTC},
        {"+HH:MM", "-00:00", ZoneOffset.UTC},
        {"+HH:MM", "+01:02", ZoneOffset.ofHoursMinutes(1, 2)},
        {"+HH:MM", "-01:02", ZoneOffset.ofHoursMinutes(-1, -2)},

        {"+HHMMss", "+0000", ZoneOffset.UTC},
        {"+HHMMss", "-0000", ZoneOffset.UTC},
        {"+HHMMss", "+0100", ZoneOffset.ofHoursMinutesSeconds(1, 0, 0)},
        {"+HHMMss", "+0159", ZoneOffset.ofHoursMinutesSeconds(1, 59, 0)},
        {"+HHMMss", "+0200", ZoneOffset.ofHoursMinutesSeconds(2, 0, 0)},
        {"+HHMMss", "+1800", ZoneOffset.ofHoursMinutesSeconds(18, 0, 0)},
        {"+HHMMss", "+010215", ZoneOffset.ofHoursMinutesSeconds(1, 2, 15)},
        {"+HHMMss", "-0100", ZoneOffset.ofHoursMinutesSeconds(-1, 0, 0)},
        {"+HHMMss", "-0200", ZoneOffset.ofHoursMinutesSeconds(-2, 0, 0)},
        {"+HHMMss", "-1800", ZoneOffset.ofHoursMinutesSeconds(-18, 0, 0)},

        {"+HHMMss", "+000000", ZoneOffset.UTC},
        {"+HHMMss", "-000000", ZoneOffset.UTC},
        {"+HHMMss", "+010000", ZoneOffset.ofHoursMinutesSeconds(1, 0, 0)},
        {"+HHMMss", "+010203", ZoneOffset.ofHoursMinutesSeconds(1, 2, 3)},
        {"+HHMMss", "+015959", ZoneOffset.ofHoursMinutesSeconds(1, 59, 59)},
        {"+HHMMss", "+020000", ZoneOffset.ofHoursMinutesSeconds(2, 0, 0)},
        {"+HHMMss", "+180000", ZoneOffset.ofHoursMinutesSeconds(18, 0, 0)},
        {"+HHMMss", "-010000", ZoneOffset.ofHoursMinutesSeconds(-1, 0, 0)},
        {"+HHMMss", "-020000", ZoneOffset.ofHoursMinutesSeconds(-2, 0, 0)},
        {"+HHMMss", "-180000", ZoneOffset.ofHoursMinutesSeconds(-18, 0, 0)},

        {"+HH:MM:ss", "+00:00", ZoneOffset.UTC},
        {"+HH:MM:ss", "-00:00", ZoneOffset.UTC},
        {"+HH:MM:ss", "+01:00", ZoneOffset.ofHoursMinutesSeconds(1, 0, 0)},
        {"+HH:MM:ss", "+01:02", ZoneOffset.ofHoursMinutesSeconds(1, 2, 0)},
        {"+HH:MM:ss", "+01:59", ZoneOffset.ofHoursMinutesSeconds(1, 59, 0)},
        {"+HH:MM:ss", "+02:00", ZoneOffset.ofHoursMinutesSeconds(2, 0, 0)},
        {"+HH:MM:ss", "+18:00", ZoneOffset.ofHoursMinutesSeconds(18, 0, 0)},
        {"+HH:MM:ss", "+01:02:15", ZoneOffset.ofHoursMinutesSeconds(1, 2, 15)},
        {"+HH:MM:ss", "-01:00", ZoneOffset.ofHoursMinutesSeconds(-1, 0, 0)},
        {"+HH:MM:ss", "-02:00", ZoneOffset.ofHoursMinutesSeconds(-2, 0, 0)},
        {"+HH:MM:ss", "-18:00", ZoneOffset.ofHoursMinutesSeconds(-18, 0, 0)},

        {"+HH:MM:ss", "+00:00:00", ZoneOffset.UTC},
        {"+HH:MM:ss", "-00:00:00", ZoneOffset.UTC},
        {"+HH:MM:ss", "+01:00:00", ZoneOffset.ofHoursMinutesSeconds(1, 0, 0)},
        {"+HH:MM:ss", "+01:02:03", ZoneOffset.ofHoursMinutesSeconds(1, 2, 3)},
        {"+HH:MM:ss", "+01:59:59", ZoneOffset.ofHoursMinutesSeconds(1, 59, 59)},
        {"+HH:MM:ss", "+02:00:00", ZoneOffset.ofHoursMinutesSeconds(2, 0, 0)},
        {"+HH:MM:ss", "+18:00:00", ZoneOffset.ofHoursMinutesSeconds(18, 0, 0)},
        {"+HH:MM:ss", "-01:00:00", ZoneOffset.ofHoursMinutesSeconds(-1, 0, 0)},
        {"+HH:MM:ss", "-02:00:00", ZoneOffset.ofHoursMinutesSeconds(-2, 0, 0)},
        {"+HH:MM:ss", "-18:00:00", ZoneOffset.ofHoursMinutesSeconds(-18, 0, 0)},

        {"+HHMMSS", "+000000", ZoneOffset.UTC},
        {"+HHMMSS", "-000000", ZoneOffset.UTC},
        {"+HHMMSS", "+010203", ZoneOffset.ofHoursMinutesSeconds(1, 2, 3)},
        {"+HHMMSS", "-010203", ZoneOffset.ofHoursMinutesSeconds(-1, -2, -3)},

        {"+HH:MM:SS", "+00:00:00", ZoneOffset.UTC},
        {"+HH:MM:SS", "-00:00:00", ZoneOffset.UTC},
        {"+HH:MM:SS", "+01:02:03", ZoneOffset.ofHoursMinutesSeconds(1, 2, 3)},
        {"+HH:MM:SS", "-01:02:03", ZoneOffset.ofHoursMinutesSeconds(-1, -2, -3)},
    };
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:75,代码来源:TestZoneOffsetParser.java

示例7: provider_offsets

import java.time.ZoneOffset; //导入方法依赖的package包/类
@DataProvider(name="offsets")
Object[][] provider_offsets() {
    return new Object[][] {
        {"+HH", "NO-OFFSET", ZoneOffset.UTC},
        {"+HH", "+01", ZoneOffset.ofHours(1)},
        {"+HH", "-01", ZoneOffset.ofHours(-1)},

        {"+HHMM", "NO-OFFSET", ZoneOffset.UTC},
        {"+HHMM", "+0102", ZoneOffset.ofHoursMinutes(1, 2)},
        {"+HHMM", "-0102", ZoneOffset.ofHoursMinutes(-1, -2)},

        {"+HH:MM", "NO-OFFSET", ZoneOffset.UTC},
        {"+HH:MM", "+01:02", ZoneOffset.ofHoursMinutes(1, 2)},
        {"+HH:MM", "-01:02", ZoneOffset.ofHoursMinutes(-1, -2)},

        {"+HHMMss", "NO-OFFSET", ZoneOffset.UTC},
        {"+HHMMss", "+0100", ZoneOffset.ofHoursMinutesSeconds(1, 0, 0)},
        {"+HHMMss", "+0102", ZoneOffset.ofHoursMinutesSeconds(1, 2, 0)},
        {"+HHMMss", "+0159", ZoneOffset.ofHoursMinutesSeconds(1, 59, 0)},
        {"+HHMMss", "+0200", ZoneOffset.ofHoursMinutesSeconds(2, 0, 0)},
        {"+HHMMss", "+1800", ZoneOffset.ofHoursMinutesSeconds(18, 0, 0)},
        {"+HHMMss", "+010215", ZoneOffset.ofHoursMinutesSeconds(1, 2, 15)},
        {"+HHMMss", "-0100", ZoneOffset.ofHoursMinutesSeconds(-1, 0, 0)},
        {"+HHMMss", "-0200", ZoneOffset.ofHoursMinutesSeconds(-2, 0, 0)},
        {"+HHMMss", "-1800", ZoneOffset.ofHoursMinutesSeconds(-18, 0, 0)},

        {"+HHMMss", "NO-OFFSET", ZoneOffset.UTC},
        {"+HHMMss", "+0100", ZoneOffset.ofHoursMinutesSeconds(1, 0, 0)},
        {"+HHMMss", "+010203", ZoneOffset.ofHoursMinutesSeconds(1, 2, 3)},
        {"+HHMMss", "+015959", ZoneOffset.ofHoursMinutesSeconds(1, 59, 59)},
        {"+HHMMss", "+0200", ZoneOffset.ofHoursMinutesSeconds(2, 0, 0)},
        {"+HHMMss", "+1800", ZoneOffset.ofHoursMinutesSeconds(18, 0, 0)},
        {"+HHMMss", "-0100", ZoneOffset.ofHoursMinutesSeconds(-1, 0, 0)},
        {"+HHMMss", "-0200", ZoneOffset.ofHoursMinutesSeconds(-2, 0, 0)},
        {"+HHMMss", "-1800", ZoneOffset.ofHoursMinutesSeconds(-18, 0, 0)},

        {"+HH:MM:ss", "NO-OFFSET", ZoneOffset.UTC},
        {"+HH:MM:ss", "+01:00", ZoneOffset.ofHoursMinutesSeconds(1, 0, 0)},
        {"+HH:MM:ss", "+01:02", ZoneOffset.ofHoursMinutesSeconds(1, 2, 0)},
        {"+HH:MM:ss", "+01:59", ZoneOffset.ofHoursMinutesSeconds(1, 59, 0)},
        {"+HH:MM:ss", "+02:00", ZoneOffset.ofHoursMinutesSeconds(2, 0, 0)},
        {"+HH:MM:ss", "+18:00", ZoneOffset.ofHoursMinutesSeconds(18, 0, 0)},
        {"+HH:MM:ss", "+01:02:15", ZoneOffset.ofHoursMinutesSeconds(1, 2, 15)},
        {"+HH:MM:ss", "-01:00", ZoneOffset.ofHoursMinutesSeconds(-1, 0, 0)},
        {"+HH:MM:ss", "-02:00", ZoneOffset.ofHoursMinutesSeconds(-2, 0, 0)},
        {"+HH:MM:ss", "-18:00", ZoneOffset.ofHoursMinutesSeconds(-18, 0, 0)},

        {"+HH:MM:ss", "NO-OFFSET", ZoneOffset.UTC},
        {"+HH:MM:ss", "+01:00", ZoneOffset.ofHoursMinutesSeconds(1, 0, 0)},
        {"+HH:MM:ss", "+01:02:03", ZoneOffset.ofHoursMinutesSeconds(1, 2, 3)},
        {"+HH:MM:ss", "+01:59:59", ZoneOffset.ofHoursMinutesSeconds(1, 59, 59)},
        {"+HH:MM:ss", "+02:00", ZoneOffset.ofHoursMinutesSeconds(2, 0, 0)},
        {"+HH:MM:ss", "+18:00", ZoneOffset.ofHoursMinutesSeconds(18, 0, 0)},
        {"+HH:MM:ss", "-01:00", ZoneOffset.ofHoursMinutesSeconds(-1, 0, 0)},
        {"+HH:MM:ss", "-02:00", ZoneOffset.ofHoursMinutesSeconds(-2, 0, 0)},
        {"+HH:MM:ss", "-18:00", ZoneOffset.ofHoursMinutesSeconds(-18, 0, 0)},

        {"+HHMMSS", "NO-OFFSET", ZoneOffset.UTC},
        {"+HHMMSS", "+010203", ZoneOffset.ofHoursMinutesSeconds(1, 2, 3)},
        {"+HHMMSS", "-010203", ZoneOffset.ofHoursMinutesSeconds(-1, -2, -3)},
        {"+HHMMSS", "+010200", ZoneOffset.ofHoursMinutesSeconds(1, 2, 0)},
        {"+HHMMSS", "-010200", ZoneOffset.ofHoursMinutesSeconds(-1, -2, 0)},

        {"+HH:MM:SS", "NO-OFFSET", ZoneOffset.UTC},
        {"+HH:MM:SS", "+01:02:03", ZoneOffset.ofHoursMinutesSeconds(1, 2, 3)},
        {"+HH:MM:SS", "-01:02:03", ZoneOffset.ofHoursMinutesSeconds(-1, -2, -3)},
        {"+HH:MM:SS", "+01:02:00", ZoneOffset.ofHoursMinutesSeconds(1, 2, 0)},
        {"+HH:MM:SS", "-01:02:00", ZoneOffset.ofHoursMinutesSeconds(-1, -2, 0)},
    };
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:71,代码来源:TestZoneOffsetPrinter.java

示例8: data_parseSuccess

import java.time.ZoneOffset; //导入方法依赖的package包/类
@DataProvider(name="parseSuccess")
Object[][] data_parseSuccess() {
    return new Object[][] {
            {"Z", 1, -1, ZoneId.of("Z"), true},
            {"UTC", 3, -1, ZoneId.of("UTC"), false},
            {"UT", 2, -1, ZoneId.of("UT"), false},
            {"GMT", 3, -1, ZoneId.of("GMT"), false},
            {"GMT0", 4, -1, ZoneId.of("GMT0"), false},

            {"+00:00", 6, -1, ZoneOffset.UTC, true},
            {"UTC+00:00", 9, -1, ZoneId.of("UTC"), false},
            {"UT+00:00", 8, -1, ZoneId.of("UT"), false},
            {"GMT+00:00", 9, -1, ZoneId.of("GMT"), false},
            {"-00:00", 6, -1, ZoneOffset.UTC, true},
            {"UTC-00:00", 9, -1, ZoneId.of("UTC"), false},
            {"UT-00:00", 8, -1, ZoneId.of("UT"), false},
            {"GMT-00:00", 9, -1, ZoneId.of("GMT"), false},

            {"+01:30", 6, -1, ZoneOffset.ofHoursMinutes(1, 30), true},
            {"UTC+01:30", 9, -1, ZoneId.of("UTC+01:30"), false},
            {"UT+02:30", 8, -1, ZoneId.of("UT+02:30"), false},
            {"GMT+03:30", 9, -1, ZoneId.of("GMT+03:30"), false},
            {"-01:30", 6, -1, ZoneOffset.ofHoursMinutes(-1, -30), true},
            {"UTC-01:30", 9, -1, ZoneId.of("UTC-01:30"), false},
            {"UT-02:30", 8, -1, ZoneId.of("UT-02:30"), false},
            {"GMT-03:30", 9, -1, ZoneId.of("GMT-03:30"), false},

            // fallback to UTC
            {"UTC-01:WW", 3, -1, ZoneId.of("UTC"), false},
            {"UT-02:WW", 2, -1, ZoneId.of("UT"), false},
            {"GMT-03:WW", 3, -1, ZoneId.of("GMT"), false},
            {"Z0", 1, -1, ZoneOffset.UTC, true},
            {"UTC1", 3, -1, ZoneId.of("UTC"), false},

            // Z not parsed as zero
            {"UTCZ", 3, -1, ZoneId.of("UTC"), false},
            {"UTZ", 2, -1, ZoneId.of("UT"), false},
            {"GMTZ", 3, -1, ZoneId.of("GMT"), false},

            // 0 not parsed
            {"UTC0", 3, -1, ZoneId.of("UTC"), false},
            {"UT0", 2, -1, ZoneId.of("UT"), false},

            // fail to parse
            {"", 0, 0, null, false},
            {"A", 0, 0, null, false},
            {"UZ", 0, 0, null, false},
            {"GMA", 0, 0, null, false},
            {"0", 0, 0, null, false},
            {"+", 0, 0, null, false},
            {"-", 0, 0, null, false},

            // zone IDs
            {"Europe/London", 13, -1, ZoneId.of("Europe/London"), false},
            {"America/New_York", 16, -1, ZoneId.of("America/New_York"), false},
            {"America/Bogusville", 0, 0, null, false},
    };
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:59,代码来源:TCKZoneIdPrinterParser.java


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