本文整理汇总了Java中java.time.temporal.TemporalAdjuster.adjustInto方法的典型用法代码示例。如果您正苦于以下问题:Java TemporalAdjuster.adjustInto方法的具体用法?Java TemporalAdjuster.adjustInto怎么用?Java TemporalAdjuster.adjustInto使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.temporal.TemporalAdjuster
的用法示例。
在下文中一共展示了TemporalAdjuster.adjustInto方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: with
import java.time.temporal.TemporalAdjuster; //导入方法依赖的package包/类
/**
* Returns an adjusted copy of this date-time.
* <p>
* This returns a {@code ZonedDateTime}, based on this one, with the date-time adjusted.
* The adjustment takes place using the specified adjuster strategy object.
* Read the documentation of the adjuster to understand what adjustment will be made.
* <p>
* A simple adjuster might simply set the one of the fields, such as the year field.
* A more complex adjuster might set the date to the last day of the month.
* A selection of common adjustments is provided in
* {@link java.time.temporal.TemporalAdjusters TemporalAdjusters}.
* These include finding the "last day of the month" and "next Wednesday".
* Key date-time classes also implement the {@code TemporalAdjuster} interface,
* such as {@link Month} and {@link java.time.MonthDay MonthDay}.
* The adjuster is responsible for handling special cases, such as the varying
* lengths of month and leap years.
* <p>
* For example this code returns a date on the last day of July:
* <pre>
* import static java.time.Month.*;
* import static java.time.temporal.TemporalAdjusters.*;
*
* result = zonedDateTime.with(JULY).with(lastDayOfMonth());
* </pre>
* <p>
* The classes {@link LocalDate} and {@link LocalTime} implement {@code TemporalAdjuster},
* thus this method can be used to change the date, time or offset:
* <pre>
* result = zonedDateTime.with(date);
* result = zonedDateTime.with(time);
* </pre>
* <p>
* {@link ZoneOffset} also implements {@code TemporalAdjuster} however using it
* as an argument typically has no effect. The offset of a {@code ZonedDateTime} is
* controlled primarily by the time-zone. As such, changing the offset does not generally
* make sense, because there is only one valid offset for the local date-time and zone.
* If the zoned date-time is in a daylight savings overlap, then the offset is used
* to switch between the two valid offsets. In all other cases, the offset is ignored.
* <p>
* The result of this method is obtained by invoking the
* {@link TemporalAdjuster#adjustInto(Temporal)} method on the
* specified adjuster passing {@code this} as the argument.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param adjuster the adjuster to use, not null
* @return a {@code ZonedDateTime} based on {@code this} with the adjustment made, not null
* @throws DateTimeException if the adjustment cannot be made
* @throws ArithmeticException if numeric overflow occurs
*/
@Override
public ZonedDateTime with(TemporalAdjuster adjuster) {
// optimizations
if (adjuster instanceof LocalDate) {
return resolveLocal(LocalDateTime.of((LocalDate) adjuster, dateTime.toLocalTime()));
} else if (adjuster instanceof LocalTime) {
return resolveLocal(LocalDateTime.of(dateTime.toLocalDate(), (LocalTime) adjuster));
} else if (adjuster instanceof LocalDateTime) {
return resolveLocal((LocalDateTime) adjuster);
} else if (adjuster instanceof OffsetDateTime) {
OffsetDateTime odt = (OffsetDateTime) adjuster;
return ofLocal(odt.toLocalDateTime(), zone, odt.getOffset());
} else if (adjuster instanceof Instant) {
Instant instant = (Instant) adjuster;
return create(instant.getEpochSecond(), instant.getNano(), zone);
} else if (adjuster instanceof ZoneOffset) {
return resolveOffset((ZoneOffset) adjuster);
}
return (ZonedDateTime) adjuster.adjustInto(this);
}
示例2: with
import java.time.temporal.TemporalAdjuster; //导入方法依赖的package包/类
/**
* Returns an adjusted copy of this date-time.
* <p>
* This returns a {@code ZonedDateTime}, based on this one, with the date-time adjusted.
* The adjustment takes place using the specified adjuster strategy object.
* Read the documentation of the adjuster to understand what adjustment will be made.
* <p>
* A simple adjuster might simply set the one of the fields, such as the year field.
* A more complex adjuster might set the date to the last day of the month.
* A selection of common adjustments is provided in {@link TemporalAdjuster}.
* These include finding the "last day of the month" and "next Wednesday".
* Key date-time classes also implement the {@code TemporalAdjuster} interface,
* such as {@link Month} and {@link java.time.MonthDay MonthDay}.
* The adjuster is responsible for handling special cases, such as the varying
* lengths of month and leap years.
* <p>
* For example this code returns a date on the last day of July:
* <pre>
* import static java.time.Month.*;
* import static java.time.temporal.Adjusters.*;
*
* result = zonedDateTime.with(JULY).with(lastDayOfMonth());
* </pre>
* <p>
* The classes {@link LocalDate} and {@link LocalTime} implement {@code TemporalAdjuster},
* thus this method can be used to change the date, time or offset:
* <pre>
* result = zonedDateTime.with(date);
* result = zonedDateTime.with(time);
* </pre>
* <p>
* {@link ZoneOffset} also implements {@code TemporalAdjuster} however using it
* as an argument typically has no effect. The offset of a {@code ZonedDateTime} is
* controlled primarily by the time-zone. As such, changing the offset does not generally
* make sense, because there is only one valid offset for the local date-time and zone.
* If the zoned date-time is in a daylight savings overlap, then the offset is used
* to switch between the two valid offsets. In all other cases, the offset is ignored.
* <p>
* The result of this method is obtained by invoking the
* {@link TemporalAdjuster#adjustInto(Temporal)} method on the
* specified adjuster passing {@code this} as the argument.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param adjuster the adjuster to use, not null
* @return a {@code ZonedDateTime} based on {@code this} with the adjustment made, not null
* @throws DateTimeException if the adjustment cannot be made
* @throws ArithmeticException if numeric overflow occurs
*/
@Override
public ZonedDateTime with(TemporalAdjuster adjuster) {
// optimizations
if (adjuster instanceof LocalDate) {
return resolveLocal(LocalDateTime.of((LocalDate) adjuster, dateTime.toLocalTime()));
} else if (adjuster instanceof LocalTime) {
return resolveLocal(LocalDateTime.of(dateTime.toLocalDate(), (LocalTime) adjuster));
} else if (adjuster instanceof LocalDateTime) {
return resolveLocal((LocalDateTime) adjuster);
} else if (adjuster instanceof OffsetDateTime) {
OffsetDateTime odt = (OffsetDateTime) adjuster;
return ofLocal(odt.toLocalDateTime(), zone, odt.getOffset());
} else if (adjuster instanceof Instant) {
Instant instant = (Instant) adjuster;
return create(instant.getEpochSecond(), instant.getNano(), zone);
} else if (adjuster instanceof ZoneOffset) {
return resolveOffset((ZoneOffset) adjuster);
}
return (ZonedDateTime) adjuster.adjustInto(this);
}
示例3: with
import java.time.temporal.TemporalAdjuster; //导入方法依赖的package包/类
/**
* Returns an adjusted copy of this time.
* <p>
* This returns an {@code OffsetTime}, based on this one, with the time adjusted.
* The adjustment takes place using the specified adjuster strategy object.
* Read the documentation of the adjuster to understand what adjustment will be made.
* <p>
* A simple adjuster might simply set the one of the fields, such as the hour field.
* A more complex adjuster might set the time to the last hour of the day.
* <p>
* The classes {@link LocalTime} and {@link ZoneOffset} implement {@code TemporalAdjuster},
* thus this method can be used to change the time or offset:
* <pre>
* result = offsetTime.with(time);
* result = offsetTime.with(offset);
* </pre>
* <p>
* The result of this method is obtained by invoking the
* {@link TemporalAdjuster#adjustInto(Temporal)} method on the
* specified adjuster passing {@code this} as the argument.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param adjuster the adjuster to use, not null
* @return an {@code OffsetTime} based on {@code this} with the adjustment made, not null
* @throws DateTimeException if the adjustment cannot be made
* @throws ArithmeticException if numeric overflow occurs
*/
@Override
public OffsetTime with(TemporalAdjuster adjuster) {
// optimizations
if (adjuster instanceof LocalTime) {
return with((LocalTime) adjuster, offset);
} else if (adjuster instanceof ZoneOffset) {
return with(time, (ZoneOffset) adjuster);
} else if (adjuster instanceof OffsetTime) {
return (OffsetTime) adjuster;
}
return (OffsetTime) adjuster.adjustInto(this);
}
示例4: with
import java.time.temporal.TemporalAdjuster; //导入方法依赖的package包/类
/**
* Returns an adjusted copy of this date-time.
* <p>
* This returns a {@code LocalDateTime}, based on this one, with the date-time adjusted.
* The adjustment takes place using the specified adjuster strategy object.
* Read the documentation of the adjuster to understand what adjustment will be made.
* <p>
* A simple adjuster might simply set the one of the fields, such as the year field.
* A more complex adjuster might set the date to the last day of the month.
* <p>
* A selection of common adjustments is provided in
* {@link java.time.temporal.TemporalAdjusters TemporalAdjusters}.
* These include finding the "last day of the month" and "next Wednesday".
* Key date-time classes also implement the {@code TemporalAdjuster} interface,
* such as {@link Month} and {@link java.time.MonthDay MonthDay}.
* The adjuster is responsible for handling special cases, such as the varying
* lengths of month and leap years.
* <p>
* For example this code returns a date on the last day of July:
* <pre>
* import static java.time.Month.*;
* import static java.time.temporal.TemporalAdjusters.*;
*
* result = localDateTime.with(JULY).with(lastDayOfMonth());
* </pre>
* <p>
* The classes {@link LocalDate} and {@link LocalTime} implement {@code TemporalAdjuster},
* thus this method can be used to change the date, time or offset:
* <pre>
* result = localDateTime.with(date);
* result = localDateTime.with(time);
* </pre>
* <p>
* The result of this method is obtained by invoking the
* {@link TemporalAdjuster#adjustInto(Temporal)} method on the
* specified adjuster passing {@code this} as the argument.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param adjuster the adjuster to use, not null
* @return a {@code LocalDateTime} based on {@code this} with the adjustment made, not null
* @throws DateTimeException if the adjustment cannot be made
* @throws ArithmeticException if numeric overflow occurs
*/
@Override
public LocalDateTime with(TemporalAdjuster adjuster) {
// optimizations
if (adjuster instanceof LocalDate) {
return with((LocalDate) adjuster, time);
} else if (adjuster instanceof LocalTime) {
return with(date, (LocalTime) adjuster);
} else if (adjuster instanceof LocalDateTime) {
return (LocalDateTime) adjuster;
}
return (LocalDateTime) adjuster.adjustInto(this);
}
示例5: with
import java.time.temporal.TemporalAdjuster; //导入方法依赖的package包/类
/**
* Returns an adjusted copy of this date-time.
* <p>
* This returns an {@code OffsetDateTime}, based on this one, with the date-time adjusted.
* The adjustment takes place using the specified adjuster strategy object.
* Read the documentation of the adjuster to understand what adjustment will be made.
* <p>
* A simple adjuster might simply set the one of the fields, such as the year field.
* A more complex adjuster might set the date to the last day of the month.
* A selection of common adjustments is provided in {@link TemporalAdjuster}.
* These include finding the "last day of the month" and "next Wednesday".
* Key date-time classes also implement the {@code TemporalAdjuster} interface,
* such as {@link Month} and {@link java.time.MonthDay MonthDay}.
* The adjuster is responsible for handling special cases, such as the varying
* lengths of month and leap years.
* <p>
* For example this code returns a date on the last day of July:
* <pre>
* import static java.time.Month.*;
* import static java.time.temporal.Adjusters.*;
*
* result = offsetDateTime.with(JULY).with(lastDayOfMonth());
* </pre>
* <p>
* The classes {@link LocalDate}, {@link LocalTime} and {@link ZoneOffset} implement
* {@code TemporalAdjuster}, thus this method can be used to change the date, time or offset:
* <pre>
* result = offsetDateTime.with(date);
* result = offsetDateTime.with(time);
* result = offsetDateTime.with(offset);
* </pre>
* <p>
* The result of this method is obtained by invoking the
* {@link TemporalAdjuster#adjustInto(Temporal)} method on the
* specified adjuster passing {@code this} as the argument.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param adjuster the adjuster to use, not null
* @return an {@code OffsetDateTime} based on {@code this} with the adjustment made, not null
* @throws DateTimeException if the adjustment cannot be made
* @throws ArithmeticException if numeric overflow occurs
*/
@Override
public OffsetDateTime with(TemporalAdjuster adjuster) {
// optimizations
if (adjuster instanceof LocalDate || adjuster instanceof LocalTime || adjuster instanceof LocalDateTime) {
return with(dateTime.with(adjuster), offset);
} else if (adjuster instanceof Instant) {
return ofInstant((Instant) adjuster, offset);
} else if (adjuster instanceof ZoneOffset) {
return with(dateTime, (ZoneOffset) adjuster);
} else if (adjuster instanceof OffsetDateTime) {
return (OffsetDateTime) adjuster;
}
return (OffsetDateTime) adjuster.adjustInto(this);
}
示例6: with
import java.time.temporal.TemporalAdjuster; //导入方法依赖的package包/类
/**
* Returns an adjusted copy of this time.
* <p>
* This returns a {@code LocalTime}, based on this one, with the time adjusted.
* The adjustment takes place using the specified adjuster strategy object.
* Read the documentation of the adjuster to understand what adjustment will be made.
* <p>
* A simple adjuster might simply set the one of the fields, such as the hour field.
* A more complex adjuster might set the time to the last hour of the day.
* <p>
* The result of this method is obtained by invoking the
* {@link TemporalAdjuster#adjustInto(Temporal)} method on the
* specified adjuster passing {@code this} as the argument.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param adjuster the adjuster to use, not null
* @return a {@code LocalTime} based on {@code this} with the adjustment made, not null
* @throws DateTimeException if the adjustment cannot be made
* @throws ArithmeticException if numeric overflow occurs
*/
@Override
public LocalTime with(TemporalAdjuster adjuster) {
// optimizations
if (adjuster instanceof LocalTime) {
return (LocalTime) adjuster;
}
return (LocalTime) adjuster.adjustInto(this);
}
示例7: with
import java.time.temporal.TemporalAdjuster; //导入方法依赖的package包/类
/**
* Returns an adjusted copy of this date-time.
* <p>
* This returns an {@code OffsetDateTime}, based on this one, with the date-time adjusted.
* The adjustment takes place using the specified adjuster strategy object.
* Read the documentation of the adjuster to understand what adjustment will be made.
* <p>
* A simple adjuster might simply set the one of the fields, such as the year field.
* A more complex adjuster might set the date to the last day of the month.
* A selection of common adjustments is provided in
* {@link java.time.temporal.TemporalAdjusters TemporalAdjusters}.
* These include finding the "last day of the month" and "next Wednesday".
* Key date-time classes also implement the {@code TemporalAdjuster} interface,
* such as {@link Month} and {@link java.time.MonthDay MonthDay}.
* The adjuster is responsible for handling special cases, such as the varying
* lengths of month and leap years.
* <p>
* For example this code returns a date on the last day of July:
* <pre>
* import static java.time.Month.*;
* import static java.time.temporal.TemporalAdjusters.*;
*
* result = offsetDateTime.with(JULY).with(lastDayOfMonth());
* </pre>
* <p>
* The classes {@link LocalDate}, {@link LocalTime} and {@link ZoneOffset} implement
* {@code TemporalAdjuster}, thus this method can be used to change the date, time or offset:
* <pre>
* result = offsetDateTime.with(date);
* result = offsetDateTime.with(time);
* result = offsetDateTime.with(offset);
* </pre>
* <p>
* The result of this method is obtained by invoking the
* {@link TemporalAdjuster#adjustInto(Temporal)} method on the
* specified adjuster passing {@code this} as the argument.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param adjuster the adjuster to use, not null
* @return an {@code OffsetDateTime} based on {@code this} with the adjustment made, not null
* @throws DateTimeException if the adjustment cannot be made
* @throws ArithmeticException if numeric overflow occurs
*/
@Override
public OffsetDateTime with(TemporalAdjuster adjuster) {
// optimizations
if (adjuster instanceof LocalDate || adjuster instanceof LocalTime || adjuster instanceof LocalDateTime) {
return with(dateTime.with(adjuster), offset);
} else if (adjuster instanceof Instant) {
return ofInstant((Instant) adjuster, offset);
} else if (adjuster instanceof ZoneOffset) {
return with(dateTime, (ZoneOffset) adjuster);
} else if (adjuster instanceof OffsetDateTime) {
return (OffsetDateTime) adjuster;
}
return (OffsetDateTime) adjuster.adjustInto(this);
}
示例8: with
import java.time.temporal.TemporalAdjuster; //导入方法依赖的package包/类
/**
* Returns an adjusted copy of this date-time.
* <p>
* This returns a {@code LocalDateTime}, based on this one, with the date-time adjusted.
* The adjustment takes place using the specified adjuster strategy object.
* Read the documentation of the adjuster to understand what adjustment will be made.
* <p>
* A simple adjuster might simply set the one of the fields, such as the year field.
* A more complex adjuster might set the date to the last day of the month.
* A selection of common adjustments is provided in {@link TemporalAdjuster}.
* These include finding the "last day of the month" and "next Wednesday".
* Key date-time classes also implement the {@code TemporalAdjuster} interface,
* such as {@link Month} and {@link java.time.MonthDay MonthDay}.
* The adjuster is responsible for handling special cases, such as the varying
* lengths of month and leap years.
* <p>
* For example this code returns a date on the last day of July:
* <pre>
* import static java.time.Month.*;
* import static java.time.temporal.Adjusters.*;
*
* result = localDateTime.with(JULY).with(lastDayOfMonth());
* </pre>
* <p>
* The classes {@link LocalDate} and {@link LocalTime} implement {@code TemporalAdjuster},
* thus this method can be used to change the date, time or offset:
* <pre>
* result = localDateTime.with(date);
* result = localDateTime.with(time);
* </pre>
* <p>
* The result of this method is obtained by invoking the
* {@link TemporalAdjuster#adjustInto(Temporal)} method on the
* specified adjuster passing {@code this} as the argument.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param adjuster the adjuster to use, not null
* @return a {@code LocalDateTime} based on {@code this} with the adjustment made, not null
* @throws DateTimeException if the adjustment cannot be made
* @throws ArithmeticException if numeric overflow occurs
*/
@Override
public LocalDateTime with(TemporalAdjuster adjuster) {
// optimizations
if (adjuster instanceof LocalDate) {
return with((LocalDate) adjuster, time);
} else if (adjuster instanceof LocalTime) {
return with(date, (LocalTime) adjuster);
} else if (adjuster instanceof LocalDateTime) {
return (LocalDateTime) adjuster;
}
return (LocalDateTime) adjuster.adjustInto(this);
}
示例9: with
import java.time.temporal.TemporalAdjuster; //导入方法依赖的package包/类
/**
* Returns an adjusted copy of this date.
* <p>
* This returns a {@code LocalDate}, based on this one, with the date adjusted.
* The adjustment takes place using the specified adjuster strategy object.
* Read the documentation of the adjuster to understand what adjustment will be made.
* <p>
* A simple adjuster might simply set the one of the fields, such as the year field.
* A more complex adjuster might set the date to the last day of the month.
* <p>
* A selection of common adjustments is provided in
* {@link java.time.temporal.TemporalAdjusters TemporalAdjusters}.
* These include finding the "last day of the month" and "next Wednesday".
* Key date-time classes also implement the {@code TemporalAdjuster} interface,
* such as {@link Month} and {@link java.time.MonthDay MonthDay}.
* The adjuster is responsible for handling special cases, such as the varying
* lengths of month and leap years.
* <p>
* For example this code returns a date on the last day of July:
* <pre>
* import static java.time.Month.*;
* import static java.time.temporal.TemporalAdjusters.*;
*
* result = localDate.with(JULY).with(lastDayOfMonth());
* </pre>
* <p>
* The result of this method is obtained by invoking the
* {@link TemporalAdjuster#adjustInto(Temporal)} method on the
* specified adjuster passing {@code this} as the argument.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param adjuster the adjuster to use, not null
* @return a {@code LocalDate} based on {@code this} with the adjustment made, not null
* @throws DateTimeException if the adjustment cannot be made
* @throws ArithmeticException if numeric overflow occurs
*/
@Override
public LocalDate with(TemporalAdjuster adjuster) {
// optimizations
if (adjuster instanceof LocalDate) {
return (LocalDate) adjuster;
}
return (LocalDate) adjuster.adjustInto(this);
}
示例10: with
import java.time.temporal.TemporalAdjuster; //导入方法依赖的package包/类
/**
* Returns an adjusted copy of this year.
* <p>
* This returns a {@code Year}, based on this one, with the year adjusted.
* The adjustment takes place using the specified adjuster strategy object.
* Read the documentation of the adjuster to understand what adjustment will be made.
* <p>
* The result of this method is obtained by invoking the
* {@link TemporalAdjuster#adjustInto(Temporal)} method on the
* specified adjuster passing {@code this} as the argument.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param adjuster the adjuster to use, not null
* @return a {@code Year} based on {@code this} with the adjustment made, not null
* @throws DateTimeException if the adjustment cannot be made
* @throws ArithmeticException if numeric overflow occurs
*/
@Override
public Year with(TemporalAdjuster adjuster) {
return (Year) adjuster.adjustInto(this);
}
示例11: with
import java.time.temporal.TemporalAdjuster; //导入方法依赖的package包/类
/**
* Returns an adjusted copy of this instant.
* <p>
* This returns an {@code Instant}, based on this one, with the instant adjusted.
* The adjustment takes place using the specified adjuster strategy object.
* Read the documentation of the adjuster to understand what adjustment will be made.
* <p>
* The result of this method is obtained by invoking the
* {@link TemporalAdjuster#adjustInto(Temporal)} method on the
* specified adjuster passing {@code this} as the argument.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param adjuster the adjuster to use, not null
* @return an {@code Instant} based on {@code this} with the adjustment made, not null
* @throws DateTimeException if the adjustment cannot be made
* @throws ArithmeticException if numeric overflow occurs
*/
@Override
public Instant with(TemporalAdjuster adjuster) {
return (Instant) adjuster.adjustInto(this);
}
示例12: with
import java.time.temporal.TemporalAdjuster; //导入方法依赖的package包/类
/**
* Returns an adjusted copy of this year-month.
* <p>
* This returns a {@code YearMonth}, based on this one, with the year-month adjusted.
* The adjustment takes place using the specified adjuster strategy object.
* Read the documentation of the adjuster to understand what adjustment will be made.
* <p>
* A simple adjuster might simply set the one of the fields, such as the year field.
* A more complex adjuster might set the year-month to the next month that
* Halley's comet will pass the Earth.
* <p>
* The result of this method is obtained by invoking the
* {@link TemporalAdjuster#adjustInto(Temporal)} method on the
* specified adjuster passing {@code this} as the argument.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param adjuster the adjuster to use, not null
* @return a {@code YearMonth} based on {@code this} with the adjustment made, not null
* @throws DateTimeException if the adjustment cannot be made
* @throws ArithmeticException if numeric overflow occurs
*/
@Override
public YearMonth with(TemporalAdjuster adjuster) {
return (YearMonth) adjuster.adjustInto(this);
}