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


Java TemporalUnit.isTimeBased方法代码示例

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


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

示例1: until

import java.time.temporal.TemporalUnit; //导入方法依赖的package包/类
@Override
public long until(Temporal endExclusive, TemporalUnit unit) {
    Objects.requireNonNull(endExclusive, "endExclusive");
    @SuppressWarnings("unchecked")
    ChronoLocalDateTime<D> end = (ChronoLocalDateTime<D>) getChronology().localDateTime(endExclusive);
    if (unit instanceof ChronoUnit) {
        if (unit.isTimeBased()) {
            long amount = end.getLong(EPOCH_DAY) - date.getLong(EPOCH_DAY);
            switch ((ChronoUnit) unit) {
                case NANOS: amount = Math.multiplyExact(amount, NANOS_PER_DAY); break;
                case MICROS: amount = Math.multiplyExact(amount, MICROS_PER_DAY); break;
                case MILLIS: amount = Math.multiplyExact(amount, MILLIS_PER_DAY); break;
                case SECONDS: amount = Math.multiplyExact(amount, SECONDS_PER_DAY); break;
                case MINUTES: amount = Math.multiplyExact(amount, MINUTES_PER_DAY); break;
                case HOURS: amount = Math.multiplyExact(amount, HOURS_PER_DAY); break;
                case HALF_DAYS: amount = Math.multiplyExact(amount, 2); break;
            }
            return Math.addExact(amount, time.until(end.toLocalTime(), unit));
        }
        ChronoLocalDate endDate = end.toLocalDate();
        if (end.toLocalTime().isBefore(time)) {
            endDate = endDate.minus(1, ChronoUnit.DAYS);
        }
        return date.until(endDate, unit);
    }
    Objects.requireNonNull(unit, "unit");
    return unit.between(this, end);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:29,代码来源:ChronoLocalDateTimeImpl.java

示例2: isSupported

import java.time.temporal.TemporalUnit; //导入方法依赖的package包/类
/**
 * Checks if the specified unit is supported.
 * <p>
 * This checks if the specified unit can be added to, or subtracted from, this date-time.
 * If false, then calling the {@link #plus(long, TemporalUnit)} and
 * {@link #minus(long, TemporalUnit) minus} methods will throw an exception.
 * <p>
 * If the unit is a {@link ChronoUnit} then the query is implemented here.
 * The supported units are:
 * <ul>
 * <li>{@code NANOS}
 * <li>{@code MICROS}
 * <li>{@code MILLIS}
 * <li>{@code SECONDS}
 * <li>{@code MINUTES}
 * <li>{@code HOURS}
 * <li>{@code HALF_DAYS}
 * </ul>
 * All other {@code ChronoUnit} instances will return false.
 * <p>
 * If the unit is not a {@code ChronoUnit}, then the result of this method
 * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)}
 * passing {@code this} as the argument.
 * Whether the unit is supported is determined by the unit.
 *
 * @param unit  the unit to check, null returns false
 * @return true if the unit can be added/subtracted, false if not
 */
@Override  // override for Javadoc
public boolean isSupported(TemporalUnit unit) {
    if (unit instanceof ChronoUnit) {
        return unit.isTimeBased();
    }
    return unit != null && unit.isSupportedBy(this);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:36,代码来源:OffsetTime.java

示例3: isSupported

import java.time.temporal.TemporalUnit; //导入方法依赖的package包/类
/**
 * Checks if the specified unit is supported.
 * <p>
 * This checks if the specified unit can be added to, or subtracted from, this date-time.
 * If false, then calling the {@link #plus(long, TemporalUnit)} and
 * {@link #minus(long, TemporalUnit) minus} methods will throw an exception.
 * <p>
 * If the unit is a {@link ChronoUnit} then the query is implemented here.
 * The supported units are:
 * <ul>
 * <li>{@code NANOS}
 * <li>{@code MICROS}
 * <li>{@code MILLIS}
 * <li>{@code SECONDS}
 * <li>{@code MINUTES}
 * <li>{@code HOURS}
 * <li>{@code HALF_DAYS}
 * <li>{@code DAYS}
 * </ul>
 * All other {@code ChronoUnit} instances will return false.
 * <p>
 * If the unit is not a {@code ChronoUnit}, then the result of this method
 * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)}
 * passing {@code this} as the argument.
 * Whether the unit is supported is determined by the unit.
 *
 * @param unit  the unit to check, null returns false
 * @return true if the unit can be added/subtracted, false if not
 */
@Override
public boolean isSupported(TemporalUnit unit) {
    if (unit instanceof ChronoUnit) {
        return unit.isTimeBased() || unit == DAYS;
    }
    return unit != null && unit.isSupportedBy(this);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:37,代码来源:Instant.java

示例4: isSupported

import java.time.temporal.TemporalUnit; //导入方法依赖的package包/类
/**
 * Checks if the specified unit is supported.
 * <p>
 * This checks if the specified unit can be added to, or subtracted from, this offset-time.
 * If false, then calling the {@link #plus(long, TemporalUnit)} and
 * {@link #minus(long, TemporalUnit) minus} methods will throw an exception.
 * <p>
 * If the unit is a {@link ChronoUnit} then the query is implemented here.
 * The supported units are:
 * <ul>
 * <li>{@code NANOS}
 * <li>{@code MICROS}
 * <li>{@code MILLIS}
 * <li>{@code SECONDS}
 * <li>{@code MINUTES}
 * <li>{@code HOURS}
 * <li>{@code HALF_DAYS}
 * </ul>
 * All other {@code ChronoUnit} instances will return false.
 * <p>
 * If the unit is not a {@code ChronoUnit}, then the result of this method
 * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)}
 * passing {@code this} as the argument.
 * Whether the unit is supported is determined by the unit.
 *
 * @param unit  the unit to check, null returns false
 * @return true if the unit can be added/subtracted, false if not
 */
@Override  // override for Javadoc
public boolean isSupported(TemporalUnit unit) {
    if (unit instanceof ChronoUnit) {
        return unit.isTimeBased();
    }
    return unit != null && unit.isSupportedBy(this);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:36,代码来源:OffsetTime.java

示例5: isSupported

import java.time.temporal.TemporalUnit; //导入方法依赖的package包/类
/**
 * Checks if the specified unit is supported.
 * <p>
 * This checks if the specified unit can be added to, or subtracted from, this time.
 * If false, then calling the {@link #plus(long, TemporalUnit)} and
 * {@link #minus(long, TemporalUnit) minus} methods will throw an exception.
 * <p>
 * If the unit is a {@link ChronoUnit} then the query is implemented here.
 * The supported units are:
 * <ul>
 * <li>{@code NANOS}
 * <li>{@code MICROS}
 * <li>{@code MILLIS}
 * <li>{@code SECONDS}
 * <li>{@code MINUTES}
 * <li>{@code HOURS}
 * <li>{@code HALF_DAYS}
 * </ul>
 * All other {@code ChronoUnit} instances will return false.
 * <p>
 * If the unit is not a {@code ChronoUnit}, then the result of this method
 * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)}
 * passing {@code this} as the argument.
 * Whether the unit is supported is determined by the unit.
 *
 * @param unit  the unit to check, null returns false
 * @return true if the unit can be added/subtracted, false if not
 */
@Override  // override for Javadoc
public boolean isSupported(TemporalUnit unit) {
    if (unit instanceof ChronoUnit) {
        return unit.isTimeBased();
    }
    return unit != null && unit.isSupportedBy(this);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:36,代码来源:LocalTime.java


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