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


Java Temporal.with方法代码示例

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


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

示例1: adjustInto

import java.time.temporal.Temporal; //导入方法依赖的package包/类
/**
 * Adjusts the specified temporal object to have this year-month.
 * <p>
 * This returns a temporal object of the same observable type as the input
 * with the year and month changed to be the same as this.
 * <p>
 * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)}
 * passing {@link ChronoField#PROLEPTIC_MONTH} as the field.
 * If the specified temporal object does not use the ISO calendar system then
 * a {@code DateTimeException} is thrown.
 * <p>
 * In most cases, it is clearer to reverse the calling pattern by using
 * {@link Temporal#with(TemporalAdjuster)}:
 * <pre>
 *   // these two lines are equivalent, but the second approach is recommended
 *   temporal = thisYearMonth.adjustInto(temporal);
 *   temporal = temporal.with(thisYearMonth);
 * </pre>
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param temporal  the target object to be adjusted, not null
 * @return the adjusted object, not null
 * @throws DateTimeException if unable to make the adjustment
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Temporal adjustInto(Temporal temporal) {
    if (Chronology.from(temporal).equals(IsoChronology.INSTANCE) == false) {
        throw new DateTimeException("Adjustment only supported on ISO date-time");
    }
    return temporal.with(PROLEPTIC_MONTH, getProlepticMonth());
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:34,代码来源:YearMonth.java

示例2: adjustInto

import java.time.temporal.Temporal; //导入方法依赖的package包/类
/**
 * Adjusts the specified temporal object to have this month-day.
 * <p>
 * This returns a temporal object of the same observable type as the input
 * with the month and day-of-month changed to be the same as this.
 * <p>
 * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)}
 * twice, passing {@link ChronoField#MONTH_OF_YEAR} and
 * {@link ChronoField#DAY_OF_MONTH} as the fields.
 * If the specified temporal object does not use the ISO calendar system then
 * a {@code DateTimeException} is thrown.
 * <p>
 * In most cases, it is clearer to reverse the calling pattern by using
 * {@link Temporal#with(TemporalAdjuster)}:
 * <pre>
 *   // these two lines are equivalent, but the second approach is recommended
 *   temporal = thisMonthDay.adjustInto(temporal);
 *   temporal = temporal.with(thisMonthDay);
 * </pre>
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param temporal  the target object to be adjusted, not null
 * @return the adjusted object, not null
 * @throws DateTimeException if unable to make the adjustment
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Temporal adjustInto(Temporal temporal) {
    if (Chronology.from(temporal).equals(IsoChronology.INSTANCE) == false) {
        throw new DateTimeException("Adjustment only supported on ISO date-time");
    }
    temporal = temporal.with(MONTH_OF_YEAR, month);
    return temporal.with(DAY_OF_MONTH, Math.min(temporal.range(DAY_OF_MONTH).getMaximum(), day));
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:36,代码来源:MonthDay.java

示例3: adjustInto

import java.time.temporal.Temporal; //导入方法依赖的package包/类
/**
 * Adjusts the specified temporal object to have this year.
 * <p>
 * This returns a temporal object of the same observable type as the input
 * with the year changed to be the same as this.
 * <p>
 * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)}
 * passing {@link ChronoField#YEAR} as the field.
 * If the specified temporal object does not use the ISO calendar system then
 * a {@code DateTimeException} is thrown.
 * <p>
 * In most cases, it is clearer to reverse the calling pattern by using
 * {@link Temporal#with(TemporalAdjuster)}:
 * <pre>
 *   // these two lines are equivalent, but the second approach is recommended
 *   temporal = thisYear.adjustInto(temporal);
 *   temporal = temporal.with(thisYear);
 * </pre>
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param temporal  the target object to be adjusted, not null
 * @return the adjusted object, not null
 * @throws DateTimeException if unable to make the adjustment
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Temporal adjustInto(Temporal temporal) {
    if (Chronology.from(temporal).equals(IsoChronology.INSTANCE) == false) {
        throw new DateTimeException("Adjustment only supported on ISO date-time");
    }
    return temporal.with(YEAR, year);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:34,代码来源:Year.java

示例4: adjustInto

import java.time.temporal.Temporal; //导入方法依赖的package包/类
/**
 * Adjusts the specified temporal object to have the same time as this object.
 * <p>
 * This returns a temporal object of the same observable type as the input
 * with the time changed to be the same as this.
 * <p>
 * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)}
 * passing {@link ChronoField#NANO_OF_DAY} as the field.
 * <p>
 * In most cases, it is clearer to reverse the calling pattern by using
 * {@link Temporal#with(TemporalAdjuster)}:
 * <pre>
 *   // these two lines are equivalent, but the second approach is recommended
 *   temporal = thisLocalTime.adjustInto(temporal);
 *   temporal = temporal.with(thisLocalTime);
 * </pre>
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param temporal  the target object to be adjusted, not null
 * @return the adjusted object, not null
 * @throws DateTimeException if unable to make the adjustment
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Temporal adjustInto(Temporal temporal) {
    return temporal.with(NANO_OF_DAY, toNanoOfDay());
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:29,代码来源:LocalTime.java

示例5: adjustInto

import java.time.temporal.Temporal; //导入方法依赖的package包/类
/**
 * Adjusts the specified temporal object to have the same date as this object.
 * <p>
 * This returns a temporal object of the same observable type as the input
 * with the date changed to be the same as this.
 * <p>
 * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)}
 * passing {@link ChronoField#EPOCH_DAY} as the field.
 * <p>
 * In most cases, it is clearer to reverse the calling pattern by using
 * {@link Temporal#with(TemporalAdjuster)}:
 * <pre>
 *   // these two lines are equivalent, but the second approach is recommended
 *   temporal = thisLocalDate.adjustInto(temporal);
 *   temporal = temporal.with(thisLocalDate);
 * </pre>
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param temporal  the target object to be adjusted, not null
 * @return the adjusted object, not null
 * @throws DateTimeException if unable to make the adjustment
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
default Temporal adjustInto(Temporal temporal) {
    return temporal.with(EPOCH_DAY, toEpochDay());
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:29,代码来源:ChronoLocalDate.java

示例6: adjustInto

import java.time.temporal.Temporal; //导入方法依赖的package包/类
/**
 * Adjusts the specified temporal object to have the same era as this object.
 * <p>
 * This returns a temporal object of the same observable type as the input
 * with the era changed to be the same as this.
 * <p>
 * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)}
 * passing {@link ChronoField#ERA} as the field.
 * <p>
 * In most cases, it is clearer to reverse the calling pattern by using
 * {@link Temporal#with(TemporalAdjuster)}:
 * <pre>
 *   // these two lines are equivalent, but the second approach is recommended
 *   temporal = thisEra.adjustInto(temporal);
 *   temporal = temporal.with(thisEra);
 * </pre>
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param temporal  the target object to be adjusted, not null
 * @return the adjusted object, not null
 * @throws DateTimeException if unable to make the adjustment
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
default Temporal adjustInto(Temporal temporal) {
    return temporal.with(ERA, getValue());
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:29,代码来源:Era.java

示例7: adjustInto

import java.time.temporal.Temporal; //导入方法依赖的package包/类
/**
 * Adjusts the specified temporal object to have the same offset as this object.
 * <p>
 * This returns a temporal object of the same observable type as the input
 * with the offset changed to be the same as this.
 * <p>
 * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)}
 * passing {@link ChronoField#OFFSET_SECONDS} as the field.
 * <p>
 * In most cases, it is clearer to reverse the calling pattern by using
 * {@link Temporal#with(TemporalAdjuster)}:
 * <pre>
 *   // these two lines are equivalent, but the second approach is recommended
 *   temporal = thisOffset.adjustInto(temporal);
 *   temporal = temporal.with(thisOffset);
 * </pre>
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param temporal  the target object to be adjusted, not null
 * @return the adjusted object, not null
 * @throws DateTimeException if unable to make the adjustment
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Temporal adjustInto(Temporal temporal) {
    return temporal.with(OFFSET_SECONDS, totalSeconds);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:29,代码来源:ZoneOffset.java


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