當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。