当前位置: 首页>>代码示例>>Java>>正文


Java LocalDateTime.plusYears方法代码示例

本文整理汇总了Java中java.time.LocalDateTime.plusYears方法的典型用法代码示例。如果您正苦于以下问题:Java LocalDateTime.plusYears方法的具体用法?Java LocalDateTime.plusYears怎么用?Java LocalDateTime.plusYears使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.time.LocalDateTime的用法示例。


在下文中一共展示了LocalDateTime.plusYears方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAYearFromNow

import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
 *  获得当天近一年
 * @return LocalDateTime
 */
public static LocalDateTime getAYearFromNow() {
    LocalDateTime date = LocalDateTime.now();
    //一年前
    return date.plusYears(-1);
}
 
开发者ID:yu199195,项目名称:happylifeplat-transaction,代码行数:10,代码来源:DateUtils.java

示例2: itShouldCreateAccessCertificate

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
@Parameters({"1", "2", "3"})
public void itShouldCreateAccessCertificate(int index) {
    Cryptotool.Keys keys = this.sut.generateKeys()
            .block();

    String gainingSerial = SecureRandomUtils.generateRandomSerial();
    String publicKey = keys.getPublicKey();
    String providingSerial = SecureRandomUtils.generateRandomSerial();
    LocalDateTime startDate = LocalDateTime.now();
    LocalDateTime endDate = startDate.plusYears(1);
    String expectedPermissions = "10001F08000040";
    PermissionsImpl permissions = PermissionsImpl.builder()
            .diagnosticsRead(true)
            .doorLocksRead(true)
            .doorLocksWrite(true)
            .keyfobPositionRead(true)
            .capabilitiesRead(true)
            .vehicleStatusRead(true)
            .chargeRead(true)
            .build();

    assertThat("sanity check", permissions.getPermissions(), is(equalToIgnoringCase(expectedPermissions)));

    Cryptotool.AccessCertificate accessCertificate = this.sut.createAccessCertificate(gainingSerial, publicKey, providingSerial, startDate, endDate, permissions)
            .block();
    assertThat(accessCertificate, is(notNullValue()));
    assertThat(accessCertificate.getAccessCertificate(), is(notNullValue()));
    assertThat(accessCertificate.getValidityStartDate(), is(startDate));
    assertThat(accessCertificate.getValidityEndDate(), is(endDate));

    String accessCertificateInHex = accessCertificate.getAccessCertificate();

    String gainingSerialValue = accessCertificateInHex.substring(0, 18);
    String publicKeyValue = accessCertificateInHex.substring(18, 146);
    String providingSerialValue = accessCertificateInHex.substring(146, 164);
    String validFromValue = accessCertificateInHex.substring(164, 174);
    String validUntilValue = accessCertificateInHex.substring(174, 184);
    String permissionsSize = accessCertificateInHex.substring(184, 186);
    String permissionsValue = accessCertificateInHex.substring(186, accessCertificateInHex.length());

    assertThat(gainingSerialValue, is(gainingSerial.toUpperCase()));
    assertThat(publicKeyValue, is(publicKey));
    assertThat(providingSerialValue, is(providingSerial.toUpperCase()));
    assertThat(validFromValue, is(equalToIgnoringCase(CryptotoolUtils.encodeAsHex(startDate))));
    assertThat(validUntilValue, is(equalToIgnoringCase(CryptotoolUtils.encodeAsHex(endDate))));
    assertThat(permissionsSize, is(notNullValue()));
    assertThat(permissionsValue, is(expectedPermissions));
}
 
开发者ID:amvnetworks,项目名称:amv-highmobility-cryptotool-wrapper,代码行数:50,代码来源:CryptotoolImplTest.java

示例3: testClacPlus

import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
 * 时间运算,计算完成后会返回新的对象,并不会改变原来的时间
 */
@Test
public void testClacPlus() {
    LocalDateTime ldt = LocalDateTime.now();

    System.out.println(ldt);

    // 加: 天
    LocalDateTime day = ldt.plusDays(1);
    System.out.println("day: " + day);

    // 加: 小时
    LocalDateTime hours = ldt.plusHours(1);
    System.out.println("hours: " + hours);

    // 加: 分钟
    LocalDateTime minutes = ldt.plusMinutes(1);
    System.out.println("minutes: " + minutes);

    // 加: 月
    LocalDateTime months = ldt.plusMonths(1);
    System.out.println("months: " + months);

    // 加: 纳秒
    LocalDateTime nanos = ldt.plusNanos(1);
    System.out.println("nanos: " + nanos);

    // 加: 秒
    LocalDateTime seconds = ldt.plusSeconds(1);
    System.out.println("seconds: " + seconds);

    // 加: 周
    LocalDateTime weeks = ldt.plusWeeks(1);
    System.out.println("weeks: " + weeks);

    // 加: 年
    LocalDateTime years = ldt.plusYears(1);
    System.out.println("years: " + years);

    System.out.println(ldt);
}
 
开发者ID:cbooy,项目名称:cakes,代码行数:44,代码来源:LocalDateTimeDemo.java

示例4: addYear

import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
 * 计算 year 年后的时间
 *
 * @param date 长日期
 * @param year 需要增加的年数
 * @return 增加后的日期
 */
public static LocalDateTime addYear(LocalDateTime date, int year) {
    return date.plusYears(year);
}
 
开发者ID:yu199195,项目名称:happylifeplat-transaction,代码行数:11,代码来源:DateUtils.java


注:本文中的java.time.LocalDateTime.plusYears方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。