java.time.ZonedDateTime.withMonth()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(4.8k)|赞(0)|评价(0)|浏览(140)

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

ZonedDateTime.withMonth介绍

[英]Returns a copy of this ZonedDateTime with the month-of-year value altered.

This operates on the local time-line, LocalDateTime#withMonth(int) of the local date-time. This is then converted back to a ZonedDateTime, using the zone ID to obtain the offset.

When converting back to 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.

This instance is immutable and unaffected by this method call.
[中]返回此ZoneDateTime的副本,更改了月份值。
这在本地时间线LocalDateTime#withMonth(int)上运行。然后将其转换回ZoneDateTime,使用分区ID获取偏移量。
当转换回ZoneDateTime时,如果本地日期时间重叠,那么如果可能,将保留偏移量,否则将使用较早的偏移量。如果存在间隙,本地日期时间将根据间隙的长度向前调整。
此实例是不可变的,不受此方法调用的影响。

代码示例

代码示例来源:origin: blynkkk/blynk-server

private ZonedDateTime adjustToStartDate(ZonedDateTime zonedStartAt, ZonedDateTime zonedNow, ZoneId zoneId) {
  if (durationType == ReportDurationType.CUSTOM) {
    ZonedDateTime zonedStartDate = getZonedFromTs(startTs, zoneId).with(LocalTime.MIN);
    if (zonedStartDate.isAfter(zonedNow)) {
      zonedStartAt = zonedStartAt
          .withDayOfMonth(zonedStartDate.getDayOfMonth())
          .withMonth(zonedStartDate.getMonthValue())
          .withYear(zonedStartDate.getYear());
    }
  }
  return zonedStartAt;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

public ZonedDateTime withMonth(int value) {
  return dt.withMonth(value);
}

代码示例来源:origin: apache/servicemix-bundles

public ZonedDateTime withMonth(int value) {
  return dt.withMonth(value);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

public ZonedDateTime withMonth(int value) {
  return dt.withMonth(value);
}

代码示例来源:origin: com.sqlapp/sqlapp-core

/**
 * 指定された日付を含む年初を取得します
 * 
 * @param date
 *            対象の日付
 * @return 年初
 */
public static ZonedDateTime beginningOfYear(ZonedDateTime date) {
  return date.withDayOfMonth(1).withMonth(1);
}

代码示例来源:origin: com.sqlapp/sqlapp-core

/**
 * ZonedDateTime型からTime型に変換します
 * 
 * @param dateTime
 * @return カレンダー型
 */
private java.sql.Time toTime(final ZonedDateTime dateTime) {
  if (dateTime == null) {
    return null;
  }
  java.sql.Time time=new java.sql.Time(dateTime.withZoneSameInstant(AbstractJava8DateConverter.INSTANT_ZONE_ID)
      .withYear(1970).withMonth(1).withDayOfMonth(1).toInstant().toEpochMilli());
  return time;
}

代码示例来源:origin: espertechinc/esper

/**
 * NOTE: Code-generation-invoked method, method name and parameter order matters
 *
 * @param zdt   zoneddatetime
 * @param year  year
 * @param month month
 * @param day   day
 * @return ldt
 */
public static ZonedDateTime actionSetYMDZonedDateTime(ZonedDateTime zdt, Integer year, Integer month, Integer day) {
  if (year != null) {
    zdt = zdt.withYear(year);
  }
  if (month != null) {
    zdt = zdt.withMonth(month);
  }
  if (day != null) {
    zdt = zdt.withDayOfMonth(day);
  }
  return zdt;
}

代码示例来源:origin: com.guestful.module/guestful.module.jsr310-extensions

@Override
public Instant instant() {
  ZonedDateTime dt = ZonedDateTime.now(zone);
  if (year != null) dt = dt.withYear(year);
  if (month != null) dt = dt.withMonth(month);
  if (day != null) dt = dt.withDayOfMonth(day);
  if (hour != null) dt = dt.withHour(hour);
  if (min != null) dt = dt.withMinute(min);
  if (sec != null) dt = dt.withSecond(sec);
  return dt.toInstant();
}

代码示例来源:origin: com.cronutils/cron-utils

private ExecutionTimeResult getNextPotentialMonth(final ZonedDateTime date, final int lowestHour, final int lowestMinute, final int lowestSecond) {
  NearestValue nearestValue;
  nearestValue = months.getNextValue(date.getMonthValue(), 0);
  final int nextMonths = nearestValue.getValue();
  if (nearestValue.getShifts() > 0) {
    return new ExecutionTimeResult(date.truncatedTo(DAYS).withMonth(1).withDayOfMonth(1).plusYears(nearestValue.getShifts()), false);
  }
  final Optional<TimeNode> optionalDays = generateDays(cronDefinition,
      ZonedDateTime.of(LocalDateTime.of(date.getYear(), nextMonths, 1, 0, 0), date.getZone()));
  if (optionalDays.isPresent()) {
    final List<Integer> days = optionalDays.get().getValues();
    return new ExecutionTimeResult(
        date.truncatedTo(SECONDS).withMonth(nextMonths).withDayOfMonth(days.get(0))
            .with(LocalTime.of(lowestHour, lowestMinute, lowestSecond)), false);
  } else {
    return new ExecutionTimeResult(toBeginOfNextMonth(date), false);
  }
}

代码示例来源:origin: com.sqlapp/sqlapp-core

/**
 * 指定された日付を含む期初を取得します
 * 
 * @param date
 *            対象の日付
 * @param accountingPeriod
 *            決算月
 * @return 期初
 */
public static ZonedDateTime beginningOfQuarter(ZonedDateTime date,
    int accountingPeriod) {
  ZonedDateTime cal = date.withMonth(accountingPeriod);
  cal = cal.plusMonths(1);
  cal = cal.withDayOfMonth(1);
  cal = truncateTime(cal);
  if (cal.compareTo(date) == 0) {
    return date;
  } else if (cal.compareTo(date) < 0) {
    cal = cal.plusYears(1);
  }
  for (int i = 0; i < 8; i++) {
    if (cal.compareTo(date) <= 0) {
      return cal;
    }
    cal = cal.plusMonths(-3);
  }
  return null;
}

代码示例来源:origin: crawler-commons/crawler-commons

parseCompareDate(zdt, "1997", "yyyyMMdd");
zdt = zdt.withMonth(7);
parseCompareDate(zdt, "1997-07", "yyyyMMdd");

相关文章

ZonedDateTime类方法