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


Java TemporalUnit.addTo方法代码示例

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


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

示例1: plus

import java.time.temporal.TemporalUnit; //导入方法依赖的package包/类
@Override
public CopticDate plus(long amountToAdd, TemporalUnit unit) {
    if (unit instanceof ChronoUnit) {
        ChronoUnit f = (ChronoUnit) unit;
        switch (f) {
            case DAYS: return plusDays(amountToAdd);
            case WEEKS: return plusDays(Math.multiplyExact(amountToAdd, 7));
            case MONTHS: return plusMonths(amountToAdd);
            case YEARS: return plusYears(amountToAdd);
            case DECADES: return plusYears(Math.multiplyExact(amountToAdd, 10));
            case CENTURIES: return plusYears(Math.multiplyExact(amountToAdd, 100));
            case MILLENNIA: return plusYears(Math.multiplyExact(amountToAdd, 1000));
        }
        throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
    }
    return unit.addTo(this, amountToAdd);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:CopticDate.java

示例2: plus

import java.time.temporal.TemporalUnit; //导入方法依赖的package包/类
/**
 * Returns a copy of this year-month with the specified amount added.
 * <p>
 * This returns a {@code YearMonth}, based on this one, with the amount
 * in terms of the unit added. If it is not possible to add the amount, because the
 * unit is not supported or for some other reason, an exception is thrown.
 * <p>
 * If the field is a {@link ChronoUnit} then the addition is implemented here.
 * The supported fields behave as follows:
 * <ul>
 * <li>{@code MONTHS} -
 *  Returns a {@code YearMonth} with the specified number of months added.
 *  This is equivalent to {@link #plusMonths(long)}.
 * <li>{@code YEARS} -
 *  Returns a {@code YearMonth} with the specified number of years added.
 *  This is equivalent to {@link #plusYears(long)}.
 * <li>{@code DECADES} -
 *  Returns a {@code YearMonth} with the specified number of decades added.
 *  This is equivalent to calling {@link #plusYears(long)} with the amount
 *  multiplied by 10.
 * <li>{@code CENTURIES} -
 *  Returns a {@code YearMonth} with the specified number of centuries added.
 *  This is equivalent to calling {@link #plusYears(long)} with the amount
 *  multiplied by 100.
 * <li>{@code MILLENNIA} -
 *  Returns a {@code YearMonth} with the specified number of millennia added.
 *  This is equivalent to calling {@link #plusYears(long)} with the amount
 *  multiplied by 1,000.
 * <li>{@code ERAS} -
 *  Returns a {@code YearMonth} with the specified number of eras added.
 *  Only two eras are supported so the amount must be one, zero or minus one.
 *  If the amount is non-zero then the year is changed such that the year-of-era
 *  is unchanged.
 * </ul>
 * <p>
 * All other {@code ChronoUnit} instances will throw an {@code UnsupportedTemporalTypeException}.
 * <p>
 * If the field is not a {@code ChronoUnit}, then the result of this method
 * is obtained by invoking {@code TemporalUnit.addTo(Temporal, long)}
 * passing {@code this} as the argument. In this case, the unit determines
 * whether and how to perform the addition.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param amountToAdd  the amount of the unit to add to the result, may be negative
 * @param unit  the unit of the amount to add, not null
 * @return a {@code YearMonth} based on this year-month with the specified amount added, not null
 * @throws DateTimeException if the addition cannot be made
 * @throws UnsupportedTemporalTypeException if the unit is not supported
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public YearMonth plus(long amountToAdd, TemporalUnit unit) {
    if (unit instanceof ChronoUnit) {
        switch ((ChronoUnit) unit) {
            case MONTHS: return plusMonths(amountToAdd);
            case YEARS: return plusYears(amountToAdd);
            case DECADES: return plusYears(Math.multiplyExact(amountToAdd, 10));
            case CENTURIES: return plusYears(Math.multiplyExact(amountToAdd, 100));
            case MILLENNIA: return plusYears(Math.multiplyExact(amountToAdd, 1000));
            case ERAS: return with(ERA, Math.addExact(getLong(ERA), amountToAdd));
        }
        throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
    }
    return unit.addTo(this, amountToAdd);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:67,代码来源:YearMonth.java

示例3: plus

import java.time.temporal.TemporalUnit; //导入方法依赖的package包/类
/**
 * Returns a copy of this time with the specified amount added.
 * <p>
 * This returns an {@code OffsetTime}, based on this one, with the amount
 * in terms of the unit added. If it is not possible to add the amount, because the
 * unit is not supported or for some other reason, an exception is thrown.
 * <p>
 * If the field is a {@link ChronoUnit} then the addition is implemented by
 * {@link LocalTime#plus(long, TemporalUnit)}.
 * The offset is not part of the calculation and will be unchanged in the result.
 * <p>
 * If the field is not a {@code ChronoUnit}, then the result of this method
 * is obtained by invoking {@code TemporalUnit.addTo(Temporal, long)}
 * passing {@code this} as the argument. In this case, the unit determines
 * whether and how to perform the addition.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param amountToAdd  the amount of the unit to add to the result, may be negative
 * @param unit  the unit of the amount to add, not null
 * @return an {@code OffsetTime} based on this time with the specified amount added, not null
 * @throws DateTimeException if the addition cannot be made
 * @throws UnsupportedTemporalTypeException if the unit is not supported
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public OffsetTime plus(long amountToAdd, TemporalUnit unit) {
    if (unit instanceof ChronoUnit) {
        return with(time.plus(amountToAdd, unit), offset);
    }
    return unit.addTo(this, amountToAdd);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:33,代码来源:OffsetTime.java

示例4: plus

import java.time.temporal.TemporalUnit; //导入方法依赖的package包/类
/**
 * Returns a copy of this date-time with the specified amount added.
 * <p>
 * This returns an {@code OffsetDateTime}, based on this one, with the amount
 * in terms of the unit added. If it is not possible to add the amount, because the
 * unit is not supported or for some other reason, an exception is thrown.
 * <p>
 * If the field is a {@link ChronoUnit} then the addition is implemented by
 * {@link LocalDateTime#plus(long, TemporalUnit)}.
 * The offset is not part of the calculation and will be unchanged in the result.
 * <p>
 * If the field is not a {@code ChronoUnit}, then the result of this method
 * is obtained by invoking {@code TemporalUnit.addTo(Temporal, long)}
 * passing {@code this} as the argument. In this case, the unit determines
 * whether and how to perform the addition.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param amountToAdd  the amount of the unit to add to the result, may be negative
 * @param unit  the unit of the amount to add, not null
 * @return an {@code OffsetDateTime} based on this date-time with the specified amount added, not null
 * @throws DateTimeException if the addition cannot be made
 * @throws UnsupportedTemporalTypeException if the unit is not supported
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public OffsetDateTime plus(long amountToAdd, TemporalUnit unit) {
    if (unit instanceof ChronoUnit) {
        return with(dateTime.plus(amountToAdd, unit), offset);
    }
    return unit.addTo(this, amountToAdd);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:33,代码来源:OffsetDateTime.java

示例5: plus

import java.time.temporal.TemporalUnit; //导入方法依赖的package包/类
/**
 * Returns a copy of this date-time with the specified amount added.
 * <p>
 * This returns a {@code ZonedDateTime}, based on this one, with the amount
 * in terms of the unit added. If it is not possible to add the amount, because the
 * unit is not supported or for some other reason, an exception is thrown.
 * <p>
 * If the field is a {@link ChronoUnit} then the addition is implemented here.
 * The zone is not part of the calculation and will be unchanged in the result.
 * The calculation for date and time units differ.
 * <p>
 * Date units operate on the local time-line.
 * The period is first added to the local date-time, then converted back
 * to a zoned date-time using the zone ID.
 * The conversion uses {@link #ofLocal(LocalDateTime, ZoneId, ZoneOffset)}
 * with the offset before the addition.
 * <p>
 * Time units operate on the instant time-line.
 * The period is first added to the local date-time, then converted back to
 * a zoned date-time using the zone ID.
 * The conversion uses {@link #ofInstant(LocalDateTime, ZoneOffset, ZoneId)}
 * with the offset before the addition.
 * <p>
 * If the field is not a {@code ChronoUnit}, then the result of this method
 * is obtained by invoking {@code TemporalUnit.addTo(Temporal, long)}
 * passing {@code this} as the argument. In this case, the unit determines
 * whether and how to perform the addition.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param amountToAdd  the amount of the unit to add to the result, may be negative
 * @param unit  the unit of the amount to add, not null
 * @return a {@code ZonedDateTime} based on this date-time with the specified amount added, not null
 * @throws DateTimeException if the addition cannot be made
 * @throws UnsupportedTemporalTypeException if the unit is not supported
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public ZonedDateTime plus(long amountToAdd, TemporalUnit unit) {
    if (unit instanceof ChronoUnit) {
        if (unit.isDateBased()) {
            return resolveLocal(dateTime.plus(amountToAdd, unit));
        } else {
            return resolveInstant(dateTime.plus(amountToAdd, unit));
        }
    }
    return unit.addTo(this, amountToAdd);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:49,代码来源:ZonedDateTime.java

示例6: plus

import java.time.temporal.TemporalUnit; //导入方法依赖的package包/类
/**
 * Returns a copy of this year with the specified amount added.
 * <p>
 * This returns a {@code Year}, based on this one, with the amount
 * in terms of the unit added. If it is not possible to add the amount, because the
 * unit is not supported or for some other reason, an exception is thrown.
 * <p>
 * If the field is a {@link ChronoUnit} then the addition is implemented here.
 * The supported fields behave as follows:
 * <ul>
 * <li>{@code YEARS} -
 *  Returns a {@code Year} with the specified number of years added.
 *  This is equivalent to {@link #plusYears(long)}.
 * <li>{@code DECADES} -
 *  Returns a {@code Year} with the specified number of decades added.
 *  This is equivalent to calling {@link #plusYears(long)} with the amount
 *  multiplied by 10.
 * <li>{@code CENTURIES} -
 *  Returns a {@code Year} with the specified number of centuries added.
 *  This is equivalent to calling {@link #plusYears(long)} with the amount
 *  multiplied by 100.
 * <li>{@code MILLENNIA} -
 *  Returns a {@code Year} with the specified number of millennia added.
 *  This is equivalent to calling {@link #plusYears(long)} with the amount
 *  multiplied by 1,000.
 * <li>{@code ERAS} -
 *  Returns a {@code Year} with the specified number of eras added.
 *  Only two eras are supported so the amount must be one, zero or minus one.
 *  If the amount is non-zero then the year is changed such that the year-of-era
 *  is unchanged.
 * </ul>
 * <p>
 * All other {@code ChronoUnit} instances will throw an {@code UnsupportedTemporalTypeException}.
 * <p>
 * If the field is not a {@code ChronoUnit}, then the result of this method
 * is obtained by invoking {@code TemporalUnit.addTo(Temporal, long)}
 * passing {@code this} as the argument. In this case, the unit determines
 * whether and how to perform the addition.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param amountToAdd  the amount of the unit to add to the result, may be negative
 * @param unit  the unit of the amount to add, not null
 * @return a {@code Year} based on this year with the specified amount added, not null
 * @throws DateTimeException if the addition cannot be made
 * @throws UnsupportedTemporalTypeException if the unit is not supported
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Year plus(long amountToAdd, TemporalUnit unit) {
    if (unit instanceof ChronoUnit) {
        switch ((ChronoUnit) unit) {
            case YEARS: return plusYears(amountToAdd);
            case DECADES: return plusYears(Math.multiplyExact(amountToAdd, 10));
            case CENTURIES: return plusYears(Math.multiplyExact(amountToAdd, 100));
            case MILLENNIA: return plusYears(Math.multiplyExact(amountToAdd, 1000));
            case ERAS: return with(ERA, Math.addExact(getLong(ERA), amountToAdd));
        }
        throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
    }
    return unit.addTo(this, amountToAdd);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:63,代码来源:Year.java


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