本文整理了Java中java.time.OffsetDateTime.with()
方法的一些代码示例,展示了OffsetDateTime.with()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OffsetDateTime.with()
方法的具体详情如下:
包路径:java.time.OffsetDateTime
类名称:OffsetDateTime
方法名:with
[英]Returns a new date-time based on this one, returning this where possible.
[中]返回基于此日期时间的新日期时间,尽可能返回此日期时间。
代码示例来源:origin: debezium/debezium
/**
* Get the ISO 8601 formatted representation of the given {@link OffsetDateTime}.
*
* @param timestamp the timestamp value
* @param adjuster the optional component that adjusts the local date value before obtaining the epoch day; may be null if no
* adjustment is necessary
* @return the ISO 8601 formatted string
*/
public static String toIsoString(OffsetDateTime timestamp, TemporalAdjuster adjuster) {
if (adjuster != null) {
timestamp = timestamp.with(adjuster);
}
return timestamp.format(FORMATTER);
}
代码示例来源:origin: debezium/debezium
/**
* Get the ISO 8601 formatted representation of the given {@link OffsetDateTime}.
*
* @param timestamp the timestamp value; may not be null
* @param adjuster the optional component that adjusts the local date value before obtaining the epoch day; may be null if no
* adjustment is necessary
* @return the ISO 8601 formatted string
*/
public static String toIsoString(OffsetDateTime timestamp, TemporalAdjuster adjuster) {
if (adjuster != null) {
timestamp = timestamp.with(adjuster);
}
return timestamp.toOffsetTime().format(FORMATTER);
}
/**
代码示例来源:origin: com.github.seratch/java-time-backport
/**
* Returns a copy of this {@code OffsetDateTime} with the specified period in seconds added.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param seconds the seconds to add, may be negative
* @return an {@code OffsetDateTime} based on this date-time with the seconds added, not null
* @throws DateTimeException if the result exceeds the supported date range
*/
public OffsetDateTime plusSeconds(long seconds) {
return with(dateTime.plusSeconds(seconds), offset);
}
代码示例来源:origin: com.github.seratch/java-time-backport
/**
* Returns a copy of this {@code OffsetDateTime} with the specified period in minutes added.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param minutes the minutes to add, may be negative
* @return an {@code OffsetDateTime} based on this date-time with the minutes added, not null
* @throws DateTimeException if the result exceeds the supported date range
*/
public OffsetDateTime plusMinutes(long minutes) {
return with(dateTime.plusMinutes(minutes), offset);
}
代码示例来源:origin: com.github.seratch/java-time-backport
/**
* Returns a copy of this {@code OffsetDateTime} with the specified period in nanoseconds added.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param nanos the nanos to add, may be negative
* @return an {@code OffsetDateTime} based on this date-time with the nanoseconds added, not null
* @throws DateTimeException if the unit cannot be added to this type
*/
public OffsetDateTime plusNanos(long nanos) {
return with(dateTime.plusNanos(nanos), offset);
}
代码示例来源:origin: com.github.seratch/java-time-backport
/**
* Returns a copy of this {@code OffsetDateTime} with the specified period in hours added.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param hours the hours to add, may be negative
* @return an {@code OffsetDateTime} based on this date-time with the hours added, not null
* @throws DateTimeException if the result exceeds the supported date range
*/
public OffsetDateTime plusHours(long hours) {
return with(dateTime.plusHours(hours), offset);
}
代码示例来源:origin: com.github.seratch/java-time-backport
/**
* Returns a copy of this {@code OffsetDateTime} with the minute-of-hour value altered.
* <p>
* The offset does not affect the calculation and will be the same in the result.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param minute the minute-of-hour to set in the result, from 0 to 59
* @return an {@code OffsetDateTime} based on this date-time with the requested minute, not null
* @throws DateTimeException if the minute value is invalid
*/
public OffsetDateTime withMinute(int minute) {
return with(dateTime.withMinute(minute), offset);
}
代码示例来源:origin: com.github.seratch/java-time-backport
/**
* Returns a copy of this {@code OffsetDateTime} with the second-of-minute value altered.
* <p>
* The offset does not affect the calculation and will be the same in the result.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param second the second-of-minute to set in the result, from 0 to 59
* @return an {@code OffsetDateTime} based on this date-time with the requested second, not null
* @throws DateTimeException if the second value is invalid
*/
public OffsetDateTime withSecond(int second) {
return with(dateTime.withSecond(second), offset);
}
代码示例来源:origin: com.github.seratch/java-time-backport
/**
* Returns a copy of this {@code OffsetDateTime} with the day-of-year altered.
* If the resulting {@code OffsetDateTime} is invalid, an exception is thrown.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param dayOfYear the day-of-year to set in the result, from 1 to 365-366
* @return an {@code OffsetDateTime} based on this date with the requested day, not null
* @throws DateTimeException if the day-of-year value is invalid
* @throws DateTimeException if the day-of-year is invalid for the year
*/
public OffsetDateTime withDayOfYear(int dayOfYear) {
return with(dateTime.withDayOfYear(dayOfYear), offset);
}
代码示例来源:origin: com.github.seratch/java-time-backport
/**
* Returns a copy of this {@code OffsetDateTime} with the nano-of-second value altered.
* <p>
* The offset does not affect the calculation and will be the same in the result.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param nanoOfSecond the nano-of-second to set in the result, from 0 to 999,999,999
* @return an {@code OffsetDateTime} based on this date-time with the requested nanosecond, not null
* @throws DateTimeException if the nanos value is invalid
*/
public OffsetDateTime withNano(int nanoOfSecond) {
return with(dateTime.withNano(nanoOfSecond), offset);
}
代码示例来源:origin: com.github.seratch/java-time-backport
/**
* Returns a copy of this {@code OffsetDateTime} with the hour-of-day value altered.
* <p>
* The offset does not affect the calculation and will be the same in the result.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param hour the hour-of-day to set in the result, from 0 to 23
* @return an {@code OffsetDateTime} based on this date-time with the requested hour, not null
* @throws DateTimeException if the hour value is invalid
*/
public OffsetDateTime withHour(int hour) {
return with(dateTime.withHour(hour), offset);
}
代码示例来源:origin: io.debezium/debezium-core
/**
* Get the ISO 8601 formatted representation of the given {@link OffsetDateTime}.
*
* @param timestamp the timestamp value
* @param adjuster the optional component that adjusts the local date value before obtaining the epoch day; may be null if no
* adjustment is necessary
* @return the ISO 8601 formatted string
*/
public static String toIsoString(OffsetDateTime timestamp, TemporalAdjuster adjuster) {
if (adjuster != null) {
timestamp = timestamp.with(adjuster);
}
return timestamp.format(FORMATTER);
}
代码示例来源:origin: com.github.seratch/java-time-backport
/**
* Returns a copy of this {@code OffsetDateTime} with the year altered.
* The offset does not affect the calculation and will be the same in the result.
* If the day-of-month is invalid for the year, it will be changed to the last valid day of the month.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param year the year to set in the result, from MIN_YEAR to MAX_YEAR
* @return an {@code OffsetDateTime} based on this date-time with the requested year, not null
* @throws DateTimeException if the year value is invalid
*/
public OffsetDateTime withYear(int year) {
return with(dateTime.withYear(year), offset);
}
代码示例来源:origin: com.github.seratch/java-time-backport
/**
* Returns a copy of this {@code OffsetDateTime} with the month-of-year altered.
* The offset does not affect the calculation and will be the same in the result.
* If the day-of-month is invalid for the year, it will be changed to the last valid day of the month.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param month the month-of-year to set in the result, from 1 (January) to 12 (December)
* @return an {@code OffsetDateTime} based on this date-time with the requested month, not null
* @throws DateTimeException if the month-of-year value is invalid
*/
public OffsetDateTime withMonth(int month) {
return with(dateTime.withMonth(month), offset);
}
代码示例来源:origin: com.github.seratch/java-time-backport
/**
* Returns a copy of this {@code OffsetDateTime} with the day-of-month altered.
* If the resulting {@code OffsetDateTime} is invalid, an exception is thrown.
* The offset does not affect the calculation and will be the same in the result.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param dayOfMonth the day-of-month to set in the result, from 1 to 28-31
* @return an {@code OffsetDateTime} based on this date-time with the requested day, not null
* @throws DateTimeException if the day-of-month value is invalid
* @throws DateTimeException if the day-of-month is invalid for the month-year
*/
public OffsetDateTime withDayOfMonth(int dayOfMonth) {
return with(dateTime.withDayOfMonth(dayOfMonth), offset);
}
代码示例来源:origin: Silverpeas/Silverpeas-Core
private OffsetDateTime normalize(final Temporal temporal) {
OffsetDateTime dateTime = asOffsetDateTime(temporal);
if (this.startDate != null) {
return TemporalConverter.applyByType(this.startDate,
t -> dateTime.with(LocalTime.MIDNIGHT.atOffset(ZoneOffset.UTC)),
t -> dateTime.with(t.toOffsetTime()));
}
return dateTime;
}
代码示例来源:origin: io.debezium/debezium-core
/**
* Get the ISO 8601 formatted representation of the given {@link OffsetDateTime}.
*
* @param timestamp the timestamp value; may not be null
* @param adjuster the optional component that adjusts the local date value before obtaining the epoch day; may be null if no
* adjustment is necessary
* @return the ISO 8601 formatted string
*/
public static String toIsoString(OffsetDateTime timestamp, TemporalAdjuster adjuster) {
if (adjuster != null) {
timestamp = timestamp.with(adjuster);
}
return timestamp.toOffsetTime().format(FORMATTER);
}
/**
代码示例来源:origin: bazaarvoice/emodb
/**
* Gets the first execution time for the given scan and upload which is at or after "now".
*/
public Instant getNextExecutionTimeAfter(Instant now) {
OffsetTime timeOfDay = OffsetTime.from(TIME_OF_DAY_FORMAT.parse(getTimeOfDay()));
// The time of the next run is based on the time past midnight UTC relative to the current time
Instant nextExecTime = now.atOffset(ZoneOffset.UTC).with(timeOfDay).toInstant();
// If the first execution would have been for earlier today move to the next execution.
while (nextExecTime.isBefore(now)) {
nextExecTime = nextExecTime.plus(Duration.ofDays(1));
}
return nextExecTime;
}
}
代码示例来源:origin: org.jadira.usertype/usertype.extended
@Override
public OffsetDateTime fromNonNullValue(Timestamp value) {
ZoneId currentDatabaseZone = getDatabaseZone() == null ? getDefaultZoneId() : getDatabaseZone();
ZoneId currentJavaZone = javaZone == null ? getDefaultZoneId() : javaZone;
OffsetDateTime dateTime = OffsetDateTime.ofInstant(Instant.ofEpochMilli(value.getTime()), currentDatabaseZone);
ZonedDateTime zonedDateTime = dateTime.with(ChronoField.NANO_OF_SECOND, value.getNanos()).atZoneSameInstant(currentJavaZone);
dateTime = zonedDateTime.toOffsetDateTime();
return dateTime;
}
代码示例来源:origin: org.jadira.usertype/usertype.extended
@Override
public OffsetTime fromNonNullValue(Timestamp value) {
ZoneId currentDatabaseZone = getDatabaseZone() == null ? getDefaultZoneOffset() : getDatabaseZone();
ZoneId currentJavaZone = javaZone == null ? getDefaultZoneOffset() : javaZone;
OffsetDateTime dateTime = OffsetDateTime.ofInstant(Instant.ofEpochMilli(value.getTime()), currentDatabaseZone);
dateTime = dateTime.with(ChronoField.NANO_OF_SECOND, value.getNanos()).atZoneSameInstant(currentJavaZone).toOffsetDateTime();
OffsetTime time = dateTime.toOffsetTime();
return time;
}
内容来源于网络,如有侵权,请联系作者删除!