本文整理了Java中java.time.LocalDateTime.withYear()
方法的一些代码示例,展示了LocalDateTime.withYear()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalDateTime.withYear()
方法的具体详情如下:
包路径:java.time.LocalDateTime
类名称:LocalDateTime
方法名:withYear
[英]Returns a copy of this 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.
This instance is immutable and unaffected by this method call.
[中]返回更改了年份的LocalDateTime的副本。时间不影响计算,结果相同。如果月份的日期对该年无效,则该日期将更改为该月的最后一个有效日期。
此实例是不可变的,不受此方法调用的影响。
代码示例来源: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 ZonedDateTime} with the year value altered.
* <p>
* This operates on the local time-line,
* {@link LocalDateTime#withYear(int) changing the year} of the local date-time.
* This is then converted back to a {@code ZonedDateTime}, using the zone ID
* to obtain the offset.
* <p>
* When converting back to {@code ZonedDateTime}, if the local date-time is in an overlap,
* then the offset will be retained if possible, otherwise the earlier offset will be used.
* If in a gap, the local date-time will be adjusted forward by the length of the gap.
* <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 ZonedDateTime} based on this date-time with the requested year, not null
* @throws DateTimeException if the year value is invalid
*/
public ZonedDateTime withYear(int year) {
return resolveLocal(dateTime.withYear(year));
}
代码示例来源:origin: espertechinc/esper
/**
* NOTE: Code-generation-invoked method, method name and parameter order matters
*
* @param ldt localdatetime
* @param year year
* @param month month
* @param day day
* @return ldt
*/
public static LocalDateTime actionSetYMDLocalDateTime(LocalDateTime ldt, Integer year, Integer month, Integer day) {
if (year != null) {
ldt = ldt.withYear(year);
}
if (month != null) {
ldt = ldt.withMonth(month);
}
if (day != null) {
ldt = ldt.withDayOfMonth(day);
}
return ldt;
}
代码示例来源:origin: com.intrbiz.bergamot/bergamot-timerange
@Override
public LocalDateTime computeNextStartTime(Clock clock)
{
LocalDateTime next = super.computeNextStartTime(clock);
if (next == null) return null;
next = next.withYear(this.year).withMonth(this.month.getMonth() + 1).withDayOfMonth(this.day);
// check the date is valid
return (next.isAfter(LocalDateTime.now(clock))) ? next : null;
}
代码示例来源:origin: com.github.jcustenborder.netty/netty-codec-syslog
result = result.withYear(LocalDateTime.now(this.zoneId).getYear());
代码示例来源:origin: net.anwiba.commons/anwiba-commons-swing-core
private LocalDateTime adapt(final LocalDateTime dateTime, final LocalDate date) {
return dateTime.withYear(date.getYear()).withMonth(date.getMonthValue()).withDayOfMonth(date.getDayOfMonth());
}
代码示例来源:origin: kousen/java_8_recipes
@Test
public void with() {
LocalDateTime start = LocalDateTime.of(2017, Month.FEBRUARY, 2, 11, 30);
LocalDateTime end = start.withMinute(45);
assertEquals("2017-02-02T11:45:00", end.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
end = start.withHour(16);
assertEquals("2017-02-02T16:30:00", end.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
end = start.withDayOfMonth(28);
assertEquals("2017-02-28T11:30:00", end.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
end = start.withDayOfYear(300);
assertEquals("2017-10-27T11:30:00", end.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
end = start.withYear(2020);
assertEquals("2020-02-02T11:30:00", end.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
}
代码示例来源:origin: baratine/baratine
cal.withYear((int) newYear);
cal.withMonth(1);
cal.withDayOfMonth(1);
内容来源于网络,如有侵权,请联系作者删除!