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

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

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

ZonedDateTime.plusMonths介绍

[英]Returns a copy of this ZonedDateTime with the specified period in months added.

This operates on the local time-line, LocalDateTime#plusMonths(long) to 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#plusMonths(长)到本地日期时间。然后将其转换回ZoneDateTime,使用分区ID获取偏移量。
当转换回ZoneDateTime时,如果本地日期时间重叠,那么如果可能,将保留偏移量,否则将使用较早的偏移量。如果存在间隙,本地日期时间将根据间隙的长度向前调整。
此实例是不可变的,不受此方法调用的影响。

代码示例

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

public ZonedDateTime plusMonths(long amount) {
  return dt.plusMonths(amount);
}

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

dateTime = dateTime.withDayOfMonth(1).with(LocalTime.MIN);
} else {
  dateTime = dateTime.plusMonths(sign * num);
  dateTime = dateTime.plusMonths(1);

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

public ZonedDateTime plusMonths(long amount) {
  return dt.plusMonths(amount);
}

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

public ZonedDateTime plusMonths(long amount) {
  return dt.plusMonths(amount);
}

代码示例来源:origin: com.github.seratch/java-time-backport

/**
 * Returns a copy of this {@code ZonedDateTime} with the specified period in months subtracted.
 * <p>
 * This operates on the local time-line,
 * {@link LocalDateTime#minusMonths(long) subtracting months} to 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 months  the months to subtract, may be negative
 * @return a {@code ZonedDateTime} based on this date-time with the months subtracted, not null
 * @throws DateTimeException if the result exceeds the supported date range
 */
public ZonedDateTime minusMonths(long months) {
  return (months == Long.MIN_VALUE ? plusMonths(Long.MAX_VALUE).plusMonths(1) : plusMonths(-months));
}

代码示例来源:origin: stackoverflow.com

ZonedDateTime firstOfMonth = zdt.with ( ChronoField.DAY_OF_MONTH , 1 );
firstOfMonth = firstOfMonth.toLocalDate ().atStartOfDay ( zoneId );
ZonedDateTime firstOfNextMonth = firstOfMonth.plusMonths ( 1 );

代码示例来源:origin: yahoo/sherlock

/**
 * Method to add month in given timestamp.
 * @param timestamp timestamp in minutes
 * @param n number of months to add
 * @return timestamp with added months
 */
public static Integer addMonth(Integer timestamp, int n) {
  ZonedDateTime zonedDateTime = TimeUtils.zonedDateTimeFromMinutes(timestamp);
  zonedDateTime = zonedDateTime.plusMonths(n);
  return (int) TimeUtils.zonedDateTimestamp(zonedDateTime) / 60;
}

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

private ZonedDateTime toBeginOfNextMonth(final ZonedDateTime datetime) {
  return datetime.truncatedTo(DAYS).plusMonths(1).withDayOfMonth(1);
}

代码示例来源:origin: stackoverflow.com

final ScheduledExecutorService executor = /* ... */ ;

Runnable task = new Runnable() {
  @Override
  public void run() {
    ZonedDateTime now = ZonedDateTime.now();
    long delay = now.until(now.plusMonths(1), ChronoUnit.MILLIS);

    try {
      // ...
    } finally {
      executor.schedule(this, delay, TimeUnit.MILLISECONDS);
    }
  }
};

int dayOfMonth = 5;

ZonedDateTime dateTime = ZonedDateTime.now();
if (dateTime.getDayOfMonth() >= dayOfMonth) {
  dateTime = dateTime.plusMonths(1);
}
dateTime = dateTime.withDayOfMonth(dayOfMonth);
executor.schedule(task,
  ZonedDateTime.now().until(dateTime, ChronoUnit.MILLIS),
  TimeUnit.MILLISECONDS);

代码示例来源:origin: UniversaBlockchain/universa

public void initFrom(ResultSet rs) throws SQLException {
  // the processing mught be already fininshed by now:
  if( rs == null || rs.isClosed() )
    throw new SQLException("resultset or connection is closed");
  recordId = rs.getLong("id");
  try {
    id = HashId.withDigest(Do.read(rs.getBinaryStream("hash")));
  } catch (IOException e) {
    throw new SQLException("failed to read hash from the recordset");
  }
  state = ItemState.values()[rs.getInt("state")];
  createdAt = getTime(rs.getLong("created_at"));
  expiresAt = getTime(rs.getLong("expires_at"));
  if(expiresAt == null) {
    // todo: what we should do with items without expiresAt?
    expiresAt = createdAt.plusMonths(3);
  }
  lockedByRecordId = rs.getInt("locked_by_id");
}

代码示例来源:origin: stackoverflow.com

java.time.ZoneId zoneId = ZoneId.of( "America/Montreal" );
ZonedDateTime zdtThisMonthStart = LocalDate.now( zoneId ).withDayOfMonth( 1 ).atStartOfDay( zoneId );
java.time.ZonedDateTime zdtNextMonthStart = zdtThisMonthStart.plusMonths( 1 );
java.time.ZonedDateTime zdtDayStart = zdtThisMonthStart; // Initialize variable to be modified in loop.

System.out.println( "JVM’s current default time zone applied implicitly by java.sql.Timestamp’s 'toString' method: " + java.util.TimeZone.getDefault( ) );

while ( zdtDayStart.isBefore( zdtNextMonthStart ) ) {
  java.time.ZonedDateTime zdtNextDayStart = zdtDayStart.plusDays( 1 );
  java.sql.Timestamp tsStart = java.sql.Timestamp.from( zdtDayStart.toInstant( ) );
  java.sql.Timestamp tsStop = java.sql.Timestamp.from( zdtNextDayStart.toInstant( ) );

  System.out.print( "In java.time, Day is: [" + zdtDayStart + "/" + zdtNextDayStart + "]. " );
  System.out.println( "In java.sql.Timestamp, Day is: [" + tsStart + "/" + tsStop + "]" );

  //
  // … Do SQL work, such as the try-catch-catch seen above in this Answer.
  //

  // Prep for next loop. Increment to next day.
  zdtDayStart = zdtDayStart.plusDays( 1 );
}

代码示例来源:origin: UniversaBlockchain/universa

@Ignore("removed functionality")
@Test(timeout = 90000)
public void declineItemFromoutWhiteList() throws Exception {
  Set<PrivateKey> stepaPrivateKeys = new HashSet<>();
  stepaPrivateKeys.add(new PrivateKey(Do.read(ROOT_PATH + "keys/stepan_mamontov.private.unikey")));
  Contract stepaCoins = Contract.fromDslFile(ROOT_PATH + "stepaCoins.yml");
  stepaCoins.setExpiresAt(ZonedDateTime.now().plusMonths(1));
  stepaCoins.addSignerKey(stepaPrivateKeys.iterator().next());
  stepaCoins.seal();
  stepaCoins.check();
  stepaCoins.traceErrors();
  node.registerItem(stepaCoins);
  ItemResult itemResult = node.waitItem(stepaCoins.getId(), 18000);
  assertEquals(ItemState.UNDEFINED, itemResult.state);
}

代码示例来源:origin: OpenGamma/Strata

public void coverage() {
 coverImmutableBean(VOLS);
 ShiftedBlackIborCapletFloorletExpiryStrikeVolatilities vols =
   ShiftedBlackIborCapletFloorletExpiryStrikeVolatilities.of(
     USD_LIBOR_3M,
     VAL_DATE_TIME.plusMonths(1),
     InterpolatedNodalSurface.of(METADATA, TIME, STRIKE, VOL, GridSurfaceInterpolator.of(TIME_SQUARE, LINEAR)),
     ConstantCurve.of("shift", 0.05));
 coverBeanEquals(VOLS, vols);
}

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

private ExecutionTimeResult getNextPotentialDayOfMonth(final ZonedDateTime date,
                            final int lowestHour,
                            final int lowestMinute,
                            final int lowestSecond,
                            final TimeNode node) {
  final NearestValue nearestValue = node.getNextValue(date.getDayOfMonth(), 0);
  if (nearestValue.getShifts() > 0) {
    return new ExecutionTimeResult(date.truncatedTo(DAYS).withDayOfMonth(1).plusMonths(nearestValue.getShifts()), false);
  }
  return new ExecutionTimeResult(date.truncatedTo(SECONDS).withDayOfMonth(nearestValue.getValue())
      .with(LocalTime.of(lowestHour, lowestMinute, lowestSecond)), false);
}

代码示例来源:origin: UniversaBlockchain/universa

@Test
public void checkTestnetNewItemExpirationDateCriteria() throws Exception {
  PrivateKey key = new PrivateKey(Do.read(rootPath + "keys/stepan_mamontov.private.unikey"));
  Contract newItem = Contract.fromDslFile(rootPath + "LamborghiniTestDrive.yml");
  newItem.addSignerKey(key);
  sealCheckTrace(newItem, true);
  newItem.setExpiresAt(ZonedDateTime.now().plusMonths(13));
  Contract contract = Contract.fromDslFile(rootPath + "LamborghiniTestDrive.yml");
  contract.addSignerKey(key);
  contract.setExpiresAt(ZonedDateTime.now().plusMonths(1));
  contract.addNewItems(newItem);
  sealCheckTrace(contract, true);
  assertFalse(contract.isSuitableForTestnet());
  // now set contract limited for testnet
  contract.setLimitedForTestnet(true);
  sealCheckTrace(contract, false);
  assertFalse(contract.isSuitableForTestnet());
}

代码示例来源:origin: UniversaBlockchain/universa

@Test
public void checkFitTestnetCriteria() throws Exception {
  PrivateKey key = new PrivateKey(Do.read(rootPath + "keys/stepan_mamontov.private.unikey"));
  Contract contract = Contract.fromDslFile(rootPath + "LamborghiniTestDrive.yml");
  contract.setExpiresAt(ZonedDateTime.now().plusMonths(1));
  contract.addSignerKey(key);
  sealCheckTrace(contract, true);
  System.out.println("Processing cost is " + contract.getProcessedCostU());
  assertTrue(contract.isSuitableForTestnet());
  // now set contract limited for testnet
  contract.setLimitedForTestnet(true);
  sealCheckTrace(contract, true);
  assertTrue(contract.isSuitableForTestnet());
}

代码示例来源:origin: UniversaBlockchain/universa

@Test
public void checkTestnetCostUCriteria() throws Exception {
  PrivateKey key = new PrivateKey(Do.read(rootPath + "keys/stepan_mamontov.private.unikey"));
  Contract contract = Contract.fromDslFile(rootPath + "LamborghiniTestDrive.yml");
  contract.setExpiresAt(ZonedDateTime.now().plusMonths(1));
  contract.addSignerKey(key);
  for (int i = 0; i < 100; i++) {
    Contract newItem = Contract.fromDslFile(rootPath + "LamborghiniTestDrive.yml");
    newItem.setExpiresAt(ZonedDateTime.now().plusMonths(1));
    newItem.addSignerKey(key);
    sealCheckTrace(newItem, true);
    contract.addNewItems(newItem);
  }
  sealCheckTrace(contract, true);
  System.out.println("Processing cost is " + contract.getProcessedCostU());
  assertTrue(contract.getProcessedCostU() > Config.maxCostUInTestMode);
  assertFalse(contract.isSuitableForTestnet());
  // now set contract limited for testnet
  contract.setLimitedForTestnet(true);
  sealCheckTrace(contract, false);
  assertFalse(contract.isSuitableForTestnet());
}

代码示例来源:origin: UniversaBlockchain/universa

@Test
public void checkTestnetExpirationDateCriteria() throws Exception {
  PrivateKey key = new PrivateKey(Do.read(rootPath + "keys/stepan_mamontov.private.unikey"));
  Contract contract = Contract.fromDslFile(rootPath + "LamborghiniTestDrive.yml");
  contract.addSignerKey(key);
  sealCheckTrace(contract, true);
  contract.setExpiresAt(ZonedDateTime.now().plusMonths(13));
  assertFalse(contract.isSuitableForTestnet());
  // now set contract limited for testnet
  contract.setLimitedForTestnet(true);
  sealCheckTrace(contract, false);
  assertFalse(contract.isSuitableForTestnet());
}

代码示例来源:origin: UniversaBlockchain/universa

@Test
public void checkTestnetKeyStrengthCriteria() throws Exception {
  PrivateKey key = new PrivateKey(Do.read(PRIVATE_KEY_PATH));
  Contract contract = createCoin100apiv3();
  contract.setExpiresAt(ZonedDateTime.now().plusMonths(1));
  contract.addSignerKey(key);
  sealCheckTrace(contract, true);
  assertFalse(contract.isSuitableForTestnet());
  // now set contract limited for testnet
  contract.setLimitedForTestnet(true);
  sealCheckTrace(contract, false);
  assertFalse(contract.isSuitableForTestnet());
}

代码示例来源:origin: UniversaBlockchain/universa

@Test(timeout = 90000)
public void transactionalValidUntil_timeIsOver() throws Exception {
  Set<PrivateKey> stepaPrivateKeys = new HashSet<>();
  Set<PublicKey> stepaPublicKeys = new HashSet<>();
  stepaPrivateKeys.add(new PrivateKey(Do.read(ROOT_PATH + "keys/stepan_mamontov.private.unikey")));
  for (PrivateKey pk : stepaPrivateKeys) {
    stepaPublicKeys.add(pk.getPublicKey());
  }
  Contract stepaCoins = Contract.fromDslFile(ROOT_PATH + "stepaCoins.yml");
  if (stepaCoins.getTransactional() == null)
    stepaCoins.createTransactionalSection();
  stepaCoins.getTransactional().setValidUntil(ZonedDateTime.now().plusMonths(-1).toEpochSecond());
  stepaCoins.addSignerKey(stepaPrivateKeys.iterator().next());
  stepaCoins.seal();
  stepaCoins.check();
  stepaCoins.traceErrors();
  Parcel parcel = createParcelWithFreshU(stepaCoins, stepaPrivateKeys);
  assertFalse(parcel.getPayloadContract().isOk());
  node.registerParcel(parcel);
  node.waitParcel(parcel.getId(), 8000);
  assertEquals(ItemState.APPROVED, node.waitItem(parcel.getPayment().getContract().getId(), 8000).state);
  assertEquals(ItemState.DECLINED, node.waitItem(parcel.getPayload().getContract().getId(), 8000).state);
}

相关文章

ZonedDateTime类方法