org.threeten.bp.LocalDateTime.with()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(11.9k)|赞(0)|评价(0)|浏览(125)

本文整理了Java中org.threeten.bp.LocalDateTime.with()方法的一些代码示例,展示了LocalDateTime.with()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalDateTime.with()方法的具体详情如下:
包路径:org.threeten.bp.LocalDateTime
类名称:LocalDateTime
方法名:with

LocalDateTime.with介绍

[英]Returns a copy of this date-time with the new date and time, checking to see if a new object is in fact required.
[中]返回带有新日期和时间的此日期时间的副本,检查是否确实需要新对象。

代码示例

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Returns a copy of this {@code LocalDateTime} with the nano-of-second value altered.
 * <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 a {@code LocalDateTime} based on this date-time with the requested nanosecond, not null
 * @throws DateTimeException if the nano value is invalid
 */
public LocalDateTime withNano(int nanoOfSecond) {
  LocalTime newTime = time.withNano(nanoOfSecond);
  return with(date, newTime);
}

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Returns a copy of this {@code LocalDateTime} with the minute-of-hour value altered.
 * <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 a {@code LocalDateTime} based on this date-time with the requested minute, not null
 * @throws DateTimeException if the minute value is invalid
 */
public LocalDateTime withMinute(int minute) {
  LocalTime newTime = time.withMinute(minute);
  return with(date, newTime);
}

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Returns a copy of this {@code LocalDateTime} with the second-of-minute value altered.
 * <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 a {@code LocalDateTime} based on this date-time with the requested second, not null
 * @throws DateTimeException if the second value is invalid
 */
public LocalDateTime withSecond(int second) {
  LocalTime newTime = time.withSecond(second);
  return with(date, newTime);
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * Returns a copy of this {@code LocalDateTime} with the hour-of-day value altered.
 * <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 a {@code LocalDateTime} based on this date-time with the requested hour, not null
 * @throws DateTimeException if the hour value is invalid
 */
public LocalDateTime withHour(int hour) {
  LocalTime newTime = time.withHour(hour);
  return with(date, newTime);
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * Returns a copy of this {@code LocalDateTime} with the minute-of-hour value altered.
 * <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 a {@code LocalDateTime} based on this date-time with the requested minute, not null
 * @throws DateTimeException if the minute value is invalid
 */
public LocalDateTime withMinute(int minute) {
  LocalTime newTime = time.withMinute(minute);
  return with(date, newTime);
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * Returns a copy of this {@code LocalDateTime} with the nano-of-second value altered.
 * <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 a {@code LocalDateTime} based on this date-time with the requested nanosecond, not null
 * @throws DateTimeException if the nano value is invalid
 */
public LocalDateTime withNano(int nanoOfSecond) {
  LocalTime newTime = time.withNano(nanoOfSecond);
  return with(date, newTime);
}

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Returns a copy of this {@code LocalDateTime} with the hour-of-day value altered.
 * <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 a {@code LocalDateTime} based on this date-time with the requested hour, not null
 * @throws DateTimeException if the hour value is invalid
 */
public LocalDateTime withHour(int hour) {
  LocalTime newTime = time.withHour(hour);
  return with(date, newTime);
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * Returns a copy of this {@code LocalDateTime} with the second-of-minute value altered.
 * <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 a {@code LocalDateTime} based on this date-time with the requested second, not null
 * @throws DateTimeException if the second value is invalid
 */
public LocalDateTime withSecond(int second) {
  LocalTime newTime = time.withSecond(second);
  return with(date, newTime);
}

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Returns a copy of this {@code LocalDateTime} with the year altered.
 * The time 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 a {@code LocalDateTime} based on this date-time with the requested year, not null
 * @throws DateTimeException if the year value is invalid
 */
public LocalDateTime withYear(int year) {
  return with(date.withYear(year), time);
}

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Returns a copy of this {@code LocalDateTime} with the month-of-year altered.
 * The time 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 a {@code LocalDateTime} based on this date-time with the requested month, not null
 * @throws DateTimeException if the month-of-year value is invalid
 */
public LocalDateTime withMonth(int month) {
  return with(date.withMonth(month), time);
}

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Returns a copy of this {@code LocalDateTime} with the day-of-year altered.
 * If the resulting {@code LocalDateTime} 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 a {@code LocalDateTime} 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 LocalDateTime withDayOfYear(int dayOfYear) {
  return with(date.withDayOfYear(dayOfYear), time);
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * Returns a copy of this {@code LocalDateTime} with the day-of-year altered.
 * If the resulting {@code LocalDateTime} 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 a {@code LocalDateTime} 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 LocalDateTime withDayOfYear(int dayOfYear) {
  return with(date.withDayOfYear(dayOfYear), time);
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * Returns a copy of this {@code LocalDateTime} with the year altered.
 * The time 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 a {@code LocalDateTime} based on this date-time with the requested year, not null
 * @throws DateTimeException if the year value is invalid
 */
public LocalDateTime withYear(int year) {
  return with(date.withYear(year), time);
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * Returns a copy of this {@code LocalDateTime} with the month-of-year altered.
 * The time 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 a {@code LocalDateTime} based on this date-time with the requested month, not null
 * @throws DateTimeException if the month-of-year value is invalid
 */
public LocalDateTime withMonth(int month) {
  return with(date.withMonth(month), time);
}

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Returns a copy of this {@code LocalDateTime} with the day-of-month altered.
 * If the resulting {@code LocalDateTime} is invalid, an exception is thrown.
 * The time 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 a {@code LocalDateTime} 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 LocalDateTime withDayOfMonth(int dayOfMonth) {
  return with(date.withDayOfMonth(dayOfMonth), time);
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * Returns a copy of this {@code LocalDateTime} with the day-of-month altered.
 * If the resulting {@code LocalDateTime} is invalid, an exception is thrown.
 * The time 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 a {@code LocalDateTime} 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 LocalDateTime withDayOfMonth(int dayOfMonth) {
  return with(date.withDayOfMonth(dayOfMonth), time);
}

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Returns a copy of this {@code LocalDateTime} with the specified period in days added.
 * <p>
 * This method adds the specified amount to the days field incrementing the
 * month and year fields as necessary to ensure the result remains valid.
 * The result is only invalid if the maximum/minimum year is exceeded.
 * <p>
 * For example, 2008-12-31 plus one day would result in 2009-01-01.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param days  the days to add, may be negative
 * @return a {@code LocalDateTime} based on this date-time with the days added, not null
 * @throws DateTimeException if the result exceeds the supported date range
 */
public LocalDateTime plusDays(long days) {
  LocalDate newDate = date.plusDays(days);
  return with(newDate, time);
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * Returns a copy of this {@code LocalDateTime} with the specified period in weeks added.
 * <p>
 * This method adds the specified amount in weeks to the days field incrementing
 * the month and year fields as necessary to ensure the result remains valid.
 * The result is only invalid if the maximum/minimum year is exceeded.
 * <p>
 * For example, 2008-12-31 plus one week would result in 2009-01-07.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param weeks  the weeks to add, may be negative
 * @return a {@code LocalDateTime} based on this date-time with the weeks added, not null
 * @throws DateTimeException if the result exceeds the supported date range
 */
public LocalDateTime plusWeeks(long weeks) {
  LocalDate newDate = date.plusWeeks(weeks);
  return with(newDate, time);
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * Returns a copy of this {@code LocalDateTime} with the specified period in days added.
 * <p>
 * This method adds the specified amount to the days field incrementing the
 * month and year fields as necessary to ensure the result remains valid.
 * The result is only invalid if the maximum/minimum year is exceeded.
 * <p>
 * For example, 2008-12-31 plus one day would result in 2009-01-01.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param days  the days to add, may be negative
 * @return a {@code LocalDateTime} based on this date-time with the days added, not null
 * @throws DateTimeException if the result exceeds the supported date range
 */
public LocalDateTime plusDays(long days) {
  LocalDate newDate = date.plusDays(days);
  return with(newDate, time);
}

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Returns a copy of this {@code LocalDateTime} with the specified period in weeks added.
 * <p>
 * This method adds the specified amount in weeks to the days field incrementing
 * the month and year fields as necessary to ensure the result remains valid.
 * The result is only invalid if the maximum/minimum year is exceeded.
 * <p>
 * For example, 2008-12-31 plus one week would result in 2009-01-07.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param weeks  the weeks to add, may be negative
 * @return a {@code LocalDateTime} based on this date-time with the weeks added, not null
 * @throws DateTimeException if the result exceeds the supported date range
 */
public LocalDateTime plusWeeks(long weeks) {
  LocalDate newDate = date.plusWeeks(weeks);
  return with(newDate, time);
}

相关文章