當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。