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

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

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

ZonedDateTime.plusMinutes介绍

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

This operates on the instant time-line, such that adding one minute will always be a duration of one minute later. This may cause the local date-time to change by an amount other than one minute. Note that this is a different approach to that used by days, months and years.

This instance is immutable and unaffected by this method call.
[中]返回此ZoneDateTime的副本,并添加指定的时间段(以分钟为单位)。
这是在即时时间线上运行的,因此添加一分钟的持续时间始终是一分钟后的持续时间。这可能会导致本地日期时间的变化量超过一分钟。请注意,这与日、月和年使用的方法不同。
此实例是不可变的,不受此方法调用的影响。

代码示例

代码示例来源:origin: prestodb/presto

public String getBearerToken(String subject)
{
  checkState(jwtSigner.isPresent(), "not configured");
  JwtBuilder jwt = Jwts.builder()
      .setSubject(subject)
      .setExpiration(Date.from(ZonedDateTime.now().plusMinutes(5).toInstant()));
  jwtSigner.get().accept(jwt);
  jwtKeyId.ifPresent(keyId -> jwt.setHeaderParam(KEY_ID, keyId));
  jwtIssuer.ifPresent(jwt::setIssuer);
  jwtAudience.ifPresent(jwt::setAudience);
  return jwt.compact();
}

代码示例来源:origin: signalapp/Signal-Server

public Pair<String, String> createFor(ZonedDateTime now, String object) {
 try {
  String expiration     = now.plusMinutes(30).format(DateTimeFormatter.ISO_INSTANT);
  String credentialDate = now.format(CREDENTIAL_DATE);
  String requestDate    = now.format(AWS_DATE_TIME  );
  String credential     = String.format("%s/%s/%s/s3/aws4_request", awsAccessId, credentialDate, region);
  String policy = String.format("{ \"expiration\": \"%s\",\n" +
                   "  \"conditions\": [\n" +
                   "    {\"bucket\": \"%s\"},\n" +
                   "    {\"key\": \"%s\"},\n" +
                   "    {\"acl\": \"private\"},\n" +
                   "    [\"starts-with\", \"$Content-Type\", \"\"],\n" +
                   "\n" +
                   "    {\"x-amz-credential\": \"%s\"},\n" +
                   "    {\"x-amz-algorithm\": \"AWS4-HMAC-SHA256\"},\n" +
                   "    {\"x-amz-date\": \"%s\" }\n" +
                   "  ]\n" +
                   "}", expiration, bucket, object, credential, requestDate);
  return new Pair<>(credential, Base64.encodeBase64String(policy.getBytes("UTF-8")));
 } catch (UnsupportedEncodingException e) {
  throw new AssertionError(e);
 }
}

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

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

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

dateTime = dateTime.withSecond(0).withNano(0);
} else {
  dateTime = dateTime.plusMinutes(sign * num);
  dateTime = dateTime.plusMinutes(1);

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

ZoneId zoneId = ZoneId.of ( "America/Montreal" );
ZonedDateTime now = ZonedDateTime.now ( zoneId );
ZonedDateTime future = now.plusMinutes ( 63 );
Duration duration = Duration.between ( now , future );

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

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

代码示例来源:origin: com.charlyghislain.authenticator/authenticator-ejb

private Date getNewTokenExpirationDate() {
  Instant instant = ZonedDateTime.now()
      .plusMinutes(tokenValidityMinutes)
      .toInstant();
  Date expirationDate = Date.from(instant);
  return expirationDate;
}

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

final DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM);
ZonedDateTime endDateTime = StringDateUtils.getZonedDateMinute(latestKey);
ZonedDateTime dateTime = StringDateUtils.getZonedDateMinute(earliestKey);
for (; ! dateTime.isAfter(endDateTime); dateTime = dateTime.plusMinutes(10)) {
  System.out.println(dateTime.format(formatter));
}

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

public ItemResult getResult() {
  ItemResult result = new ItemResult(ItemState.PENDING, false, ZonedDateTime.now(), ZonedDateTime.now().plusMinutes(5));
  result.extraDataBinder = new Binder();
  result.errors = new ArrayList<>();
  return result;
}

代码示例来源:origin: org.apache.james/james-server-jmap

@Override
public ContinuationToken generateContinuationToken(String username) {
  Preconditions.checkNotNull(username);
  ZonedDateTime expirationTime = zonedDateTimeProvider.get().plusMinutes(15);
  return new ContinuationToken(username,
    expirationTime,
    signatureHandler.sign(
        Joiner.on(ContinuationToken.SEPARATOR)
          .join(username,
            DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(expirationTime))));
}

代码示例来源:origin: prestosql/presto

public String getBearerToken(String subject)
{
  checkState(jwtSigner.isPresent(), "not configured");
  JwtBuilder jwt = Jwts.builder()
      .setSubject(subject)
      .setExpiration(Date.from(ZonedDateTime.now().plusMinutes(5).toInstant()));
  jwtSigner.get().accept(jwt);
  jwtKeyId.ifPresent(keyId -> jwt.setHeaderParam(KEY_ID, keyId));
  jwtIssuer.ifPresent(jwt::setIssuer);
  jwtAudience.ifPresent(jwt::setAudience);
  return jwt.compact();
}

代码示例来源:origin: org.mycore/mycore-restapi

public static Optional<String> getToken(MCRUserInformation userInformation, String remoteIp) {
  ZonedDateTime currentTime = ZonedDateTime.now(ZoneOffset.UTC);
  return Optional.ofNullable(userInformation)
    .map(MCRJWTUtil::getJWTBuilder)
    .map(b -> {
      return b.withAudience(AUDIENCE)
        .withClaim(MCRJWTUtil.JWT_CLAIM_IP, remoteIp)
        .withExpiresAt(Date.from(currentTime.plusMinutes(EXPIRATION_TIME_MINUTES).toInstant()))
        .withNotBefore(Date.from(currentTime.minusMinutes(EXPIRATION_TIME_MINUTES).toInstant()))
        .sign(MCRJWTUtil.getJWTAlgorithm());
    });
}

代码示例来源:origin: com.powsybl/powsybl-afs-ws-server

private String issueToken(String login) {
    Key key = keyGenerator.generateKey();
    ZonedDateTime now = ZonedDateTime.now();
    return Jwts.builder()
        .signWith(SignatureAlgorithm.HS512, key)
        .compressWith(CompressionCodecs.DEFLATE)
        .setSubject(login)
        .setIssuer(uriInfo.getAbsolutePath().toString())
        .setIssuedAt(Date.from(now.toInstant()))
        .setExpiration(Date.from(now.plusMinutes(tokenValidity).toInstant()))
        .compact();
  }
}

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

ZonedDateTime nextDay = start.plusDays ( 1 );
ZonedDateTime zdt = start;
while ( zdt.isBefore ( nextDay ) ) {
  ZonedDateTime zdtMinute = zdt;
  ZonedDateTime zdtNextHour = zdtMinute.plusHours ( 1 );
  while ( zdtMinute.isBefore ( zdtNextHour ) ) {
    System.out.println ( zdtMinute.toString () );
    // Prepare for next loop.
    zdtMinute = zdtMinute.plusMinutes ( 1 );
  }
  // Prepare for next loop.
  zdt = zdt.plusHours ( 1 );
}

代码示例来源:origin: commercetools/commercetools-jvm-sdk

@Test
public void queryForCreatedAtIsNotIn() {
  createdAtTest((m, date) -> m.isNotIn(singletonList(date.plusMinutes(2))));
}

代码示例来源:origin: org.apache.james/james-server-jmap

@Test
public void isValidShouldReturnFalseOnNonValidSignatures() throws Exception {
  zonedDateTimeProvider.setFixedDateTime(DATE);
  ContinuationToken pirateContinuationToken = new ContinuationToken("user", DATE.plusMinutes(15), "fake");
  assertThat(tokenManager.isValid(pirateContinuationToken)).isFalse();
}

代码示例来源:origin: org.apache.james/james-server-jmap

@Test
public void getValidityShouldReturnFalseOnNonValidSignatures() throws Exception {
  zonedDateTimeProvider.setFixedDateTime(DATE);
  ContinuationToken pirateContinuationToken = new ContinuationToken("user", DATE.plusMinutes(15), "fake");
  assertThat(tokenManager.getValidity(pirateContinuationToken)).isEqualTo(TokenStatus.INVALID);
}

代码示例来源:origin: commercetools/commercetools-jvm-sdk

@Test
public void queryForCreatedAtIsNot() {
  createdAtTest((m, date) -> m.isNot(date.plusMinutes(1)));
}

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

@Test
public void checkContractExpiresAtResentFutureTime() throws Exception{
  Contract futureContract = Contract.fromDslFile(rootPath + "simple_root_contract.yml");
  futureContract.addSignerKeyFromFile(rootPath+"_xer0yfe2nn1xthc.private.unikey");
  futureContract.getDefinition().setExpiresAt(futureContract.getCreatedAt().plusMinutes(1));
  futureContract.seal();
  assertTrue(futureContract.check());
  System.out.println("Contract is valid: " + futureContract.isOk());
}

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

@Test
public void checkRegisterContractExpiresAtReсentFutureTime() throws Exception{
  Contract futureContract = Contract.fromDslFile(ROOT_PATH + "simple_root_contract.yml");
  futureContract.addSignerKeyFromFile(ROOT_PATH+"_xer0yfe2nn1xthc.private.unikey");
  futureContract.getDefinition().setExpiresAt(futureContract.getCreatedAt().plusMinutes(1));
  futureContract.seal();
  assertTrue(futureContract.check());
  System.out.println("Contract is valid: " + futureContract.isOk());
  registerAndCheckApproved(futureContract);
}

相关文章

ZonedDateTime类方法