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


Java ChronoUnit.YEARS属性代码示例

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


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

示例1: data_minus_long_TemporalUnit

@DataProvider(name="minus_long_TemporalUnit")
Object[][] data_minus_long_TemporalUnit() {
    return new Object[][] {
        {Year.of(1), 1, ChronoUnit.YEARS, Year.of(0), null},
        {Year.of(1), -12, ChronoUnit.YEARS, Year.of(13), null},
        {Year.of(1), 0, ChronoUnit.YEARS, Year.of(1), null},
        {Year.of(999999999), 0, ChronoUnit.YEARS, Year.of(999999999), null},
        {Year.of(-999999999), 0, ChronoUnit.YEARS, Year.of(-999999999), null},
        {Year.of(0), -999999999, ChronoUnit.YEARS, Year.of(999999999), null},
        {Year.of(0), 999999999, ChronoUnit.YEARS, Year.of(-999999999), null},

        {Year.of(999999999), 1, ChronoUnit.ERAS, Year.of(-999999999 + 1), null},
        {Year.of(105), 1, ChronoUnit.CENTURIES, Year.of(5), null},
        {Year.of(15), 1, ChronoUnit.DECADES, Year.of(5), null},

        {Year.of(-999999999), 1, ChronoUnit.YEARS, null, DateTimeException.class},
        {Year.of(1), -999999999, ChronoUnit.YEARS, null, DateTimeException.class},

        {Year.of(1), 0, ChronoUnit.DAYS, null, DateTimeException.class},
        {Year.of(1), 0, ChronoUnit.WEEKS, null, DateTimeException.class},
        {Year.of(1), 0, ChronoUnit.MONTHS, null, DateTimeException.class},
    };
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:TCKYear.java

示例2: data_plus_long_TemporalUnit

@DataProvider(name="plus_long_TemporalUnit")
Object[][] data_plus_long_TemporalUnit() {
    return new Object[][] {
        {Year.of(1), 1, ChronoUnit.YEARS, Year.of(2), null},
        {Year.of(1), -12, ChronoUnit.YEARS, Year.of(-11), null},
        {Year.of(1), 0, ChronoUnit.YEARS, Year.of(1), null},
        {Year.of(999999999), 0, ChronoUnit.YEARS, Year.of(999999999), null},
        {Year.of(-999999999), 0, ChronoUnit.YEARS, Year.of(-999999999), null},
        {Year.of(0), -999999999, ChronoUnit.YEARS, Year.of(-999999999), null},
        {Year.of(0), 999999999, ChronoUnit.YEARS, Year.of(999999999), null},

        {Year.of(-1), 1, ChronoUnit.ERAS, Year.of(2), null},
        {Year.of(5), 1, ChronoUnit.CENTURIES, Year.of(105), null},
        {Year.of(5), 1, ChronoUnit.DECADES, Year.of(15), null},

        {Year.of(999999999), 1, ChronoUnit.YEARS, null, DateTimeException.class},
        {Year.of(-999999999), -1, ChronoUnit.YEARS, null, DateTimeException.class},

        {Year.of(1), 0, ChronoUnit.DAYS, null, DateTimeException.class},
        {Year.of(1), 0, ChronoUnit.WEEKS, null, DateTimeException.class},
        {Year.of(1), 0, ChronoUnit.MONTHS, null, DateTimeException.class},
    };
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:TCKYear.java

示例3: getParentChronoUnit

/**
 * Returns the parent ChronoUnit for the given ChronoUnit.
 *
 * @param chronoUnit desired ChronoUnit
 * @return parent ChronoUnit of the given ChronoUnit
 */
@NotNull
public static ChronoUnit getParentChronoUnit(@NotNull ChronoUnit chronoUnit) {
    switch (requireNonNull(chronoUnit)) {
        case NANOS:
            return ChronoUnit.SECONDS;
        case MICROS:
            return ChronoUnit.SECONDS;
        case MILLIS:
            return ChronoUnit.SECONDS;
        case SECONDS:
            return ChronoUnit.MINUTES;
        case MINUTES:
            return ChronoUnit.HOURS;
        case HOURS:
            return ChronoUnit.DAYS;
        case DAYS:
            return ChronoUnit.WEEKS;
        case WEEKS:
            return ChronoUnit.MONTHS;
        case MONTHS:
            return ChronoUnit.YEARS;
        case YEARS:
            return ChronoUnit.DECADES;
        case DECADES:
            return ChronoUnit.CENTURIES;
        case CENTURIES:
            return ChronoUnit.ERAS;
        default:
            throw new UnsupportedOperationException("Unsupported chrono unit: " + chronoUnit);
    }
}
 
开发者ID:BFergerson,项目名称:Chronetic,代码行数:37,代码来源:ChronoScale.java

示例4: getChildChronoUnit

/**
 * Returns the child ChronoUnit for the given ChronoUnit.
 *
 * @param chronoUnit desired ChronoUnit
 * @return child ChronoUnit of the given ChronoUnit
 */
@NotNull
public static ChronoUnit getChildChronoUnit(@NotNull ChronoUnit chronoUnit) {
    switch (requireNonNull(chronoUnit)) {
        case MICROS:
            return ChronoUnit.NANOS;
        case MILLIS:
            return ChronoUnit.MICROS;
        case SECONDS:
            return ChronoUnit.MILLIS;
        case MINUTES:
            return ChronoUnit.SECONDS;
        case HOURS:
            return ChronoUnit.MINUTES;
        case DAYS:
            return ChronoUnit.HOURS;
        case WEEKS:
            return ChronoUnit.DAYS;
        case MONTHS:
            return ChronoUnit.WEEKS;
        case YEARS:
            return ChronoUnit.MONTHS;
        case DECADES:
            return ChronoUnit.YEARS;
        case MILLENNIA:
            return ChronoUnit.DECADES;
        case ERAS:
            return ChronoUnit.MILLENNIA;
        default:
            throw new UnsupportedOperationException("Unsupported chrono unit: " + chronoUnit);
    }
}
 
开发者ID:BFergerson,项目名称:Chronetic,代码行数:37,代码来源:ChronoScale.java

示例5: from

/**
 * Obtains an instance of {@code Period} from a temporal amount.
 * <p>
 * This obtains a period based on the specified amount.
 * A {@code TemporalAmount} represents an  amount of time, which may be
 * date-based or time-based, which this factory extracts to a {@code Period}.
 * <p>
 * The conversion loops around the set of units from the amount and uses
 * the {@link ChronoUnit#YEARS YEARS}, {@link ChronoUnit#MONTHS MONTHS}
 * and {@link ChronoUnit#DAYS DAYS} units to create a period.
 * If any other units are found then an exception is thrown.
 * <p>
 * If the amount is a {@code ChronoPeriod} then it must use the ISO chronology.
 *
 * @param amount  the temporal amount to convert, not null
 * @return the equivalent period, not null
 * @throws DateTimeException if unable to convert to a {@code Period}
 * @throws ArithmeticException if the amount of years, months or days exceeds an int
 */
public static Period from(TemporalAmount amount) {
    if (amount instanceof Period) {
        return (Period) amount;
    }
    if (amount instanceof ChronoPeriod) {
        if (IsoChronology.INSTANCE.equals(((ChronoPeriod) amount).getChronology()) == false) {
            throw new DateTimeException("Period requires ISO chronology: " + amount);
        }
    }
    Objects.requireNonNull(amount, "amount");
    int years = 0;
    int months = 0;
    int days = 0;
    for (TemporalUnit unit : amount.getUnits()) {
        long unitAmount = amount.get(unit);
        if (unit == ChronoUnit.YEARS) {
            years = Math.toIntExact(unitAmount);
        } else if (unit == ChronoUnit.MONTHS) {
            months = Math.toIntExact(unitAmount);
        } else if (unit == ChronoUnit.DAYS) {
            days = Math.toIntExact(unitAmount);
        } else {
            throw new DateTimeException("Unit must be Years, Months or Days, but was " + unit);
        }
    }
    return create(years, months, days);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:46,代码来源:Period.java

示例6: data_query

@DataProvider(name="query")
Object[][] data_query() {
    return new Object[][] {
            {TEST_2008, TemporalQueries.chronology(), IsoChronology.INSTANCE},
            {TEST_2008, TemporalQueries.zoneId(), null},
            {TEST_2008, TemporalQueries.precision(), ChronoUnit.YEARS},
            {TEST_2008, TemporalQueries.zone(), null},
            {TEST_2008, TemporalQueries.offset(), null},
            {TEST_2008, TemporalQueries.localDate(), null},
            {TEST_2008, TemporalQueries.localTime(), null},
    };
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:TCKYear.java

示例7: get

@Override
public long get(TemporalUnit unit) {
    if (unit == ChronoUnit.YEARS) {
        return years;
    } else if (unit == ChronoUnit.MONTHS) {
        return months;
    } else if (unit == ChronoUnit.DAYS) {
        return days;
    } else {
        throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:12,代码来源:ChronoPeriodImpl.java

示例8: data_plus_long_TemporalUnit

@DataProvider(name="plus_long_TemporalUnit")
Object[][] data_plus_long_TemporalUnit() {
    return new Object[][] {
        {YearMonth.of(1, 10), 1, ChronoUnit.YEARS, YearMonth.of(2, 10), null},
        {YearMonth.of(1, 10), -12, ChronoUnit.YEARS, YearMonth.of(-11, 10), null},
        {YearMonth.of(1, 10), 0, ChronoUnit.YEARS, YearMonth.of(1, 10), null},
        {YearMonth.of(999999999, 12), 0, ChronoUnit.YEARS, YearMonth.of(999999999, 12), null},
        {YearMonth.of(-999999999, 1), 0, ChronoUnit.YEARS, YearMonth.of(-999999999, 1), null},
        {YearMonth.of(0, 1), -999999999, ChronoUnit.YEARS, YearMonth.of(-999999999, 1), null},
        {YearMonth.of(0, 12), 999999999, ChronoUnit.YEARS, YearMonth.of(999999999, 12), null},

        {YearMonth.of(1, 10), 1, ChronoUnit.MONTHS, YearMonth.of(1, 11), null},
        {YearMonth.of(1, 10), -12, ChronoUnit.MONTHS, YearMonth.of(0, 10), null},
        {YearMonth.of(1, 10), 0, ChronoUnit.MONTHS, YearMonth.of(1, 10), null},
        {YearMonth.of(999999999, 12), 0, ChronoUnit.MONTHS, YearMonth.of(999999999, 12), null},
        {YearMonth.of(-999999999, 1), 0, ChronoUnit.MONTHS, YearMonth.of(-999999999, 1), null},
        {YearMonth.of(-999999999, 2), -1, ChronoUnit.MONTHS, YearMonth.of(-999999999, 1), null},
        {YearMonth.of(999999999, 3), 9, ChronoUnit.MONTHS, YearMonth.of(999999999, 12), null},

        {YearMonth.of(-1, 10), 1, ChronoUnit.ERAS, YearMonth.of(2, 10), null},
        {YearMonth.of(5, 10), 1, ChronoUnit.CENTURIES, YearMonth.of(105, 10), null},
        {YearMonth.of(5, 10), 1, ChronoUnit.DECADES, YearMonth.of(15, 10), null},

        {YearMonth.of(999999999, 12), 1, ChronoUnit.MONTHS, null, DateTimeException.class},
        {YearMonth.of(-999999999, 1), -1, ChronoUnit.MONTHS, null, DateTimeException.class},

        {YearMonth.of(1, 1), 0, ChronoUnit.DAYS, null, DateTimeException.class},
        {YearMonth.of(1, 1), 0, ChronoUnit.WEEKS, null, DateTimeException.class},
    };
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:30,代码来源:TCKYearMonth.java

示例9: data_minus_long_TemporalUnit

@DataProvider(name="minus_long_TemporalUnit")
Object[][] data_minus_long_TemporalUnit() {
    return new Object[][] {
        {YearMonth.of(1, 10), 1, ChronoUnit.YEARS, YearMonth.of(0, 10), null},
        {YearMonth.of(1, 10), 12, ChronoUnit.YEARS, YearMonth.of(-11, 10), null},
        {YearMonth.of(1, 10), 0, ChronoUnit.YEARS, YearMonth.of(1, 10), null},
        {YearMonth.of(999999999, 12), 0, ChronoUnit.YEARS, YearMonth.of(999999999, 12), null},
        {YearMonth.of(-999999999, 1), 0, ChronoUnit.YEARS, YearMonth.of(-999999999, 1), null},
        {YearMonth.of(0, 1), 999999999, ChronoUnit.YEARS, YearMonth.of(-999999999, 1), null},
        {YearMonth.of(0, 12), -999999999, ChronoUnit.YEARS, YearMonth.of(999999999, 12), null},

        {YearMonth.of(1, 10), 1, ChronoUnit.MONTHS, YearMonth.of(1, 9), null},
        {YearMonth.of(1, 10), 12, ChronoUnit.MONTHS, YearMonth.of(0, 10), null},
        {YearMonth.of(1, 10), 0, ChronoUnit.MONTHS, YearMonth.of(1, 10), null},
        {YearMonth.of(999999999, 12), 0, ChronoUnit.MONTHS, YearMonth.of(999999999, 12), null},
        {YearMonth.of(-999999999, 1), 0, ChronoUnit.MONTHS, YearMonth.of(-999999999, 1), null},
        {YearMonth.of(-999999999, 2), 1, ChronoUnit.MONTHS, YearMonth.of(-999999999, 1), null},
        {YearMonth.of(999999999, 11), -1, ChronoUnit.MONTHS, YearMonth.of(999999999, 12), null},

        {YearMonth.of(1, 10), 1, ChronoUnit.ERAS, YearMonth.of(0, 10), null},
        {YearMonth.of(5, 10), 1, ChronoUnit.CENTURIES, YearMonth.of(-95, 10), null},
        {YearMonth.of(5, 10), 1, ChronoUnit.DECADES, YearMonth.of(-5, 10), null},

        {YearMonth.of(999999999, 12), -1, ChronoUnit.MONTHS, null, DateTimeException.class},
        {YearMonth.of(-999999999, 1), 1, ChronoUnit.MONTHS, null, DateTimeException.class},

        {YearMonth.of(1, 1), 0, ChronoUnit.DAYS, null, DateTimeException.class},
        {YearMonth.of(1, 1), 0, ChronoUnit.WEEKS, null, DateTimeException.class},
    };
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:30,代码来源:TCKYearMonth.java

示例10: data_goodTemporalUnit

@DataProvider(name="GoodTemporalUnit")
Object[][] data_goodTemporalUnit() {
    return new Object[][] {
        {2, ChronoUnit.DAYS},
        {2, ChronoUnit.MONTHS},
        {2, ChronoUnit.YEARS},
    };
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:TCKPeriod.java

示例11: get

/**
 * Gets the value of the requested unit.
 * <p>
 * This returns a value for each of the three supported units,
 * {@link ChronoUnit#YEARS YEARS}, {@link ChronoUnit#MONTHS MONTHS} and
 * {@link ChronoUnit#DAYS DAYS}.
 * All other units throw an exception.
 *
 * @param unit the {@code TemporalUnit} for which to return the value
 * @return the long value of the unit
 * @throws DateTimeException if the unit is not supported
 * @throws UnsupportedTemporalTypeException if the unit is not supported
 */
@Override
public long get(TemporalUnit unit) {
    if (unit == ChronoUnit.YEARS) {
        return getYears();
    } else if (unit == ChronoUnit.MONTHS) {
        return getMonths();
    } else if (unit == ChronoUnit.DAYS) {
        return getDays();
    } else {
        throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:Period.java


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