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


Java Temporal.minus方法代码示例

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


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

示例1: subtractFrom

import java.time.temporal.Temporal; //导入方法依赖的package包/类
@Override
public Temporal subtractFrom(Temporal temporal) {
    validateChrono(temporal);
    if (months == 0) {
        if (years != 0) {
            temporal = temporal.minus(years, YEARS);
        }
    } else {
        long monthRange = monthRange();
        if (monthRange > 0) {
            temporal = temporal.minus(years * monthRange + months, MONTHS);
        } else {
            if (years != 0) {
                temporal = temporal.minus(years, YEARS);
            }
            temporal = temporal.minus(months, MONTHS);
        }
    }
    if (days != 0) {
        temporal = temporal.minus(days, DAYS);
    }
    return temporal;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:ChronoPeriodImpl.java

示例2: subtractFrom

import java.time.temporal.Temporal; //导入方法依赖的package包/类
@Override
public Temporal subtractFrom(Temporal temporal) {
    for(Map.Entry<TemporalUnit, Long> entry : values.entrySet()) {
        temporal = temporal.minus(entry.getValue(), entry.getKey());
    }
    return temporal;
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:8,代码来源:TimePeriod.java

示例3: subtractFrom

import java.time.temporal.Temporal; //导入方法依赖的package包/类
@Override
public Temporal subtractFrom(Temporal temporal) {
    return temporal.minus(value, unit);
}
 
开发者ID:StefaniniInspiring,项目名称:pugtsdb,代码行数:5,代码来源:Retention.java

示例4: subtractFrom

import java.time.temporal.Temporal; //导入方法依赖的package包/类
/**
 * Subtracts this period from the specified temporal object.
 * <p>
 * This returns a temporal object of the same observable type as the input
 * with this period subtracted.
 * If the temporal has a chronology, it must be the ISO chronology.
 * <p>
 * In most cases, it is clearer to reverse the calling pattern by using
 * {@link Temporal#minus(TemporalAmount)}.
 * <pre>
 *   // these two lines are equivalent, but the second approach is recommended
 *   dateTime = thisPeriod.subtractFrom(dateTime);
 *   dateTime = dateTime.minus(thisPeriod);
 * </pre>
 * <p>
 * The calculation operates as follows.
 * First, the chronology of the temporal is checked to ensure it is ISO chronology or null.
 * Second, if the months are zero, the years are subtracted if non-zero, otherwise
 * the combination of years and months is subtracted if non-zero.
 * Finally, any days are subtracted.
 * <p>
 * This approach ensures that a partial period can be subtracted from a partial date.
 * For example, a period of years and/or months can be subtracted from a {@code YearMonth},
 * but a period including days cannot.
 * The approach also subtracts years and months together when necessary, which ensures
 * correct behaviour at the end of the month.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param temporal  the temporal object to adjust, not null
 * @return an object of the same type with the adjustment made, not null
 * @throws DateTimeException if unable to subtract
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Temporal subtractFrom(Temporal temporal) {
    validateChrono(temporal);
    if (months == 0) {
        if (years != 0) {
            temporal = temporal.minus(years, YEARS);
        }
    } else {
        long totalMonths = toTotalMonths();
        if (totalMonths != 0) {
            temporal = temporal.minus(totalMonths, MONTHS);
        }
    }
    if (days != 0) {
        temporal = temporal.minus(days, DAYS);
    }
    return temporal;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:53,代码来源:Period.java

示例5: subtractFrom

import java.time.temporal.Temporal; //导入方法依赖的package包/类
@Override
public Temporal subtractFrom(Temporal temporal) {
    return temporal.minus(amount, unit);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:5,代码来源:MockSimplePeriod.java

示例6: subtractFrom

import java.time.temporal.Temporal; //导入方法依赖的package包/类
/**
 * Subtracts this duration from the specified temporal object.
 * <p>
 * This returns a temporal object of the same observable type as the input
 * with this duration subtracted.
 * <p>
 * In most cases, it is clearer to reverse the calling pattern by using
 * {@link Temporal#minus(TemporalAmount)}.
 * <pre>
 *   // these two lines are equivalent, but the second approach is recommended
 *   dateTime = thisDuration.subtractFrom(dateTime);
 *   dateTime = dateTime.minus(thisDuration);
 * </pre>
 * <p>
 * The calculation will subtract the seconds, then nanos.
 * Only non-zero amounts will be added.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param temporal  the temporal object to adjust, not null
 * @return an object of the same type with the adjustment made, not null
 * @throws DateTimeException if unable to subtract
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Temporal subtractFrom(Temporal temporal) {
    if (seconds != 0) {
        temporal = temporal.minus(seconds, SECONDS);
    }
    if (nanos != 0) {
        temporal = temporal.minus(nanos, NANOS);
    }
    return temporal;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:35,代码来源:Duration.java


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