gpt4 book ai didi

java.time.Year.plus()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-17 22:26:40 28 4
gpt4 key购买 nike

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

Year.plus介绍

暂无

代码示例

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

/**
 * {@inheritDoc}
 * @throws DateTimeException {@inheritDoc}
 * @throws ArithmeticException {@inheritDoc}
 */
@Override
public Year minus(long amountToSubtract, TemporalUnit unit) {
  return (amountToSubtract == Long.MIN_VALUE ? plus(Long.MAX_VALUE, unit).plus(1, unit) : plus(-amountToSubtract, unit));
}

代码示例来源:origin: chhsiao90/nitmproxy

public static Certificate newCert(String parentCertFile, String keyFile, String host) {
  try {
    Date before = Date.from(Instant.now());
    Date after = Date.from(Year.now().plus(3, ChronoUnit.YEARS).atDay(1).atStartOfDay(ZoneId.systemDefault()).toInstant());
    X509CertificateHolder parent = readPemFromFile(parentCertFile);
    PEMKeyPair pemKeyPair = readPemFromFile(keyFile);
    KeyPair keyPair = new JcaPEMKeyConverter()
        .setProvider(PROVIDER)
        .getKeyPair(pemKeyPair);
    X509v3CertificateBuilder x509 = new JcaX509v3CertificateBuilder(
        parent.getSubject(),
        new BigInteger(64, new SecureRandom()),
        before,
        after,
        new X500Name("CN=" + host),
        keyPair.getPublic());
    ContentSigner signer = new JcaContentSignerBuilder("SHA256WithRSAEncryption")
        .build(keyPair.getPrivate());
    JcaX509CertificateConverter x509CertificateConverter = new JcaX509CertificateConverter()
        .setProvider(PROVIDER);
    return new Certificate(
        keyPair,
        x509CertificateConverter.getCertificate(x509.build(signer)),
        x509CertificateConverter.getCertificate(parent));
  } catch (Exception e) {
    throw new IllegalStateException(e);
  }
}

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com