本文整理了Java中java.time.LocalDateTime.withMonth()
方法的一些代码示例,展示了LocalDateTime.withMonth()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalDateTime.withMonth()
方法的具体详情如下:
包路径:java.time.LocalDateTime
类名称:LocalDateTime
方法名:withMonth
[英]Returns a copy of this 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.
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 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: qala-io/datagen
public static LocalDateTime startOfYear() {
return startOfMonth().withMonth(1);
}
public static LocalDateTime startOfMonth() {
代码示例来源:origin: com.github.seratch/java-time-backport
/**
* Returns a copy of this {@code ZonedDateTime} with the month-of-year value altered.
* <p>
* This operates on the local time-line,
* {@link LocalDateTime#withMonth(int) changing the month} 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 month the month-of-year to set in the result, from 1 (January) to 12 (December)
* @return a {@code ZonedDateTime} based on this date-time with the requested month, not null
* @throws DateTimeException if the month-of-year value is invalid
*/
public ZonedDateTime withMonth(int month) {
return resolveLocal(dateTime.withMonth(month));
}
代码示例来源: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: OpenNMS/opennms
private Instant adjustEndTime(Date date){
LocalDateTime current = LocalDateTime.ofInstant(Instant.ofEpochMilli(date.getTime()),
UTC).withMinute(59).withSecond(59).withNano(999999999);
if(this.strategy == IndexStrategy.YEARLY){
current = current.withMonth(12);
}
if(this.strategy == IndexStrategy.MONTHLY
|| this.strategy == IndexStrategy.YEARLY){
current = current.with(TemporalAdjusters.lastDayOfMonth());
}
if(this.strategy == IndexStrategy.DAILY
|| this.strategy == IndexStrategy.MONTHLY
|| this.strategy == IndexStrategy.YEARLY){
current = current.withHour(23);
}
return current.atZone(UTC).toInstant();
}
}
代码示例来源:origin: com.intrbiz.bergamot/bergamot-timerange
@Override
public LocalDateTime computeNextStartTime(Clock clock)
{
LocalDateTime next = super.computeNextStartTime(clock);
if (next == null) return null;
next = next.withMonth(this.month.getMonth() + 1);
// is it next year?
if (! next.isAfter(LocalDateTime.now(clock))) next = next.plusYears(1);
// check the date is valid
return (next.isAfter(LocalDateTime.now(clock))) ? next : null;
}
代码示例来源:origin: org.opennms.features.flows/org.opennms.features.flows.elastic
private Instant adjustEndTime(Date date){
LocalDateTime current = LocalDateTime.ofInstant(Instant.ofEpochMilli(date.getTime()),
UTC).withMinute(59).withSecond(59).withNano(999999999);
if(this.strategy == IndexStrategy.YEARLY){
current = current.withMonth(12);
}
if(this.strategy == IndexStrategy.MONTHLY
|| this.strategy == IndexStrategy.YEARLY){
current = current.with(TemporalAdjusters.lastDayOfMonth());
}
if(this.strategy == IndexStrategy.DAILY
|| this.strategy == IndexStrategy.MONTHLY
|| this.strategy == IndexStrategy.YEARLY){
current = current.withHour(23);
}
return current.atZone(UTC).toInstant();
}
}
代码示例来源: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: stackoverflow.com
public LocalDateTime truncateTo(LocalDateTime dt, Time interval) {
switch(interval) {
case MONTH_6:
if(dt.getMonthValue() > 6)
dt = dt.withMonth(7);
else
dt = dt.withMonth(1);
case MONTH:
dt = dt.withDayOfMonth(1);
case DAY:
dt = dt.withHour(0);
case HOUR:
dt = dt.withMinute(0);
dt = dt.withSecond(0);
dt = dt.withNano(0);
break;
}
return dt;
}
代码示例来源: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: cn.bestwu.simpleframework/simpleframework-core
/**
* 取得当季度第一天
*
* @return LocalDateHelper
*/
public LocalDateTimeHelper getFirstDayOfQuarter() {
return LocalDateTimeHelper
.of(localDateTime.withMonth(localDateTime.getMonth().firstMonthOfQuarter().getValue())
.with(TemporalAdjusters.firstDayOfMonth())).zoneOffset(zoneOffset);
}
代码示例来源:origin: cn.bestwu.simpleframework/simpleframework-web
/**
* 取得当季度第一天
*
* @return LocalDateHelper
*/
public LocalDateTimeHelper getFirstDayOfQuarter() {
return LocalDateTimeHelper
.of(localDateTime.withMonth(localDateTime.getMonth().firstMonthOfQuarter().getValue())
.with(TemporalAdjusters.firstDayOfMonth())).zoneOffset(zoneOffset);
}
代码示例来源:origin: cn.bestwu.simpleframework/simpleframework-web
/**
* 取得当季度最后一天
*
* @return LocalDateHelper
*/
public LocalDateTimeHelper getLastDayOfQuarter() {
return LocalDateTimeHelper
.of(localDateTime
.withMonth(localDateTime.getMonth().firstMonthOfQuarter().plus(2).getValue())
.with(TemporalAdjusters.lastDayOfMonth())).zoneOffset(zoneOffset);
}
代码示例来源:origin: cn.bestwu.simpleframework/simpleframework-core
/**
* 取得当季度最后一天
*
* @return LocalDateHelper
*/
public LocalDateTimeHelper getLastDayOfQuarter() {
return LocalDateTimeHelper
.of(localDateTime
.withMonth(localDateTime.getMonth().firstMonthOfQuarter().plus(2).getValue())
.with(TemporalAdjusters.lastDayOfMonth())).zoneOffset(zoneOffset);
}
代码示例来源:origin: cn.bestwu.simpleframework/simpleframework-web
/**
* 取得下季度第一天
*
* @return LocalDateHelper
*/
public LocalDateTimeHelper getFirstDayOfNextQuarter() {
return LocalDateTimeHelper
.of(localDateTime
.withMonth(localDateTime.getMonth().firstMonthOfQuarter().plus(3).getValue())
.with(TemporalAdjusters.firstDayOfMonth())).zoneOffset(zoneOffset);
}
代码示例来源:origin: cn.bestwu.simpleframework/simpleframework-core
/**
* 取得下季度第一天
*
* @return LocalDateHelper
*/
public LocalDateTimeHelper getFirstDayOfNextQuarter() {
return LocalDateTimeHelper
.of(localDateTime
.withMonth(localDateTime.getMonth().firstMonthOfQuarter().plus(3).getValue())
.with(TemporalAdjusters.firstDayOfMonth())).zoneOffset(zoneOffset);
}
代码示例来源:origin: org.mnode.ical4j/ical4j
LocalDateTime ldt = LocalDateTime.now(zoneId)
.with(TemporalAdjusters.firstInMonth(transitionRuleDayOfWeek))
.withMonth(transitionRuleMonthValue)
.with(transitionRule.getLocalTime());
Month month = ldt.getMonth();
observance.getProperties().add(offsetTo);
observance.getProperties().add(rrule);
observance.getProperties().add(new DtStart(startDate.withMonth(transitionRule.getMonth().getValue())
.withDayOfMonth(transitionRule.getDayOfMonthIndicator())
.with(transitionRule.getDayOfWeek()).format(DateTimeFormatter.ofPattern(DATE_TIME_TPL))));
代码示例来源:origin: ical4j/ical4j
LocalDateTime ldt = LocalDateTime.now(zoneId)
.with(TemporalAdjusters.firstInMonth(transitionRuleDayOfWeek))
.withMonth(transitionRuleMonthValue)
.with(transitionRule.getLocalTime());
Month month = ldt.getMonth();
observance.getProperties().add(offsetTo);
observance.getProperties().add(rrule);
observance.getProperties().add(new DtStart(startDate.withMonth(transitionRule.getMonth().getValue())
.withDayOfMonth(transitionRule.getDayOfMonthIndicator())
.with(transitionRule.getDayOfWeek()).format(DateTimeFormatter.ofPattern(DATE_TIME_TPL))));
代码示例来源:origin: baratine/baratine
cal.withMonth(month + months);
cal.withDayOfMonth(1);
cal.withMonth(1);
cal.withDayOfMonth(1);
代码示例来源:origin: baratine/baratine
cal.withMonth(cal.getMonthValue() + 1);
cal.withDayOfMonth(1);
内容来源于网络,如有侵权,请联系作者删除!