Java LocalDate類| minusYears()方法與示例

LocalDate類minusYears()方法 (LocalDate Class minusYears() method)

  • minusYears() method is available in java.time package.

    minusYears()方法在java.time包中可用。

  • minusYears() method is used to subtract the given years from this LocalDate and return the LocalDate.

    minusYears()方法用于從此LocalDate中減去給定的年份并返回LocalDate。

  • minusYears() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    minusYears()方法是一種非靜態方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。

  • minusYears() method may throw an exception at the time of performing subtraction.

    minusYears()方法在執行減法時可能會引發異常。

    DateTimeException: This exception may throw when the calculated result value exceeds the limit.

    DateTimeException :當計算結果值超出限制時,可能引發此異常。

Syntax:

句法:

    public LocalDate minusYears(long yrs_val);

Parameter(s):

參數:

  • long yrs_val – represents the years to be subtracted from this LocalDate.

    long yrs_val –表示要從此LocalDate中減去的年份。

Return value:

返回值:

The return type of this method is LocalDate, it returns the LocalDate that holds the value subtracted the given years from this LocalDate.

此方法的返回類型為LocalDate ,它返回LocalDate,該LocalDate保留從此LocalDate中減去給定年份的值。

Example:

例:

// Java program to demonstrate the example 
// of minusYears(long yrs_val) method of LocalDate
import java.time.*;
public class MinusYearsOfLocalDate {
public static void main(String args[]) {
long years = 3;
// Instantiates two LocalDate
LocalDate l_da1 = LocalDate.parse("2007-04-04");
LocalDate l_da2 = LocalDate.of(2008, Month.FEBRUARY, 06);
// Display l_da1,l_da2 and years
System.out.println("LocalDate l_da1,l_da2 : ");
System.out.println("l_da1: " + l_da1);
System.out.println("l_da2: " + l_da2);
System.out.println("years to subtract: " + years);
System.out.println();
// Here, this method subtracts the
// given years from this date l_da1
// i.e. here we are subtracting 3
// years from the date l_da1
LocalDate minus_yrs = l_da1.minusYears(years);
// Display minus_yrs
System.out.println("l_da1.minusYears(years): " + minus_yrs);
// Here, this method subtracts the
// given years from this date l_da2
// i.e. here we are subtracting 3
// years from the date l_da2
minus_yrs = l_da2.minusYears(years);
// Display minus_yrs
System.out.println("l_da2.minusYears(years): " + minus_yrs);
}
}

Output

輸出量

LocalDate l_da1,l_da2 : 
l_da1: 2007-04-04
l_da2: 2008-02-06
years to subtract: 3l_da1.minusYears(years): 2004-04-04
l_da2.minusYears(years): 2005-02-06

翻譯自: https://www.includehelp.com/java/localdate-minusyears-method-with-example.aspx

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/379338.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/379338.shtml
英文地址,請注明出處:http://en.pswp.cn/news/379338.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

ffmpeg 命令添加圖片水印

使用ffplay預覽一下: ffplay -i cctvhttp.flv -vf “moviewatermark.png[watermark];[in][watermark]overlay x10:y10[out]” -x 640 -y 480 參數: 有兩個過濾器movie\overlay movie:讀取watermark.png輸出 [watermark]可以理解自定義的的變…

實驗9 SQL Server 的觸發器

實驗9 SQL Server 的觸發器一、實驗目的 1.了解觸發器的觸發過程和類型 2.通過執行SQL腳本,掌握創建觸發器并測試觸發器 3.掌握通過使用觸發器維護數據完整性的方法。 二、實驗要求 1.按指定要求創建觸發器。 三、實驗步驟 1.創建一個名為tr_age的觸發器&#xff0…

struts2學習筆記二--準備struts2的學習和開發環境

準備struts2的學習和開發環境1 導包2 參照開發包自帶的例子在web.xml文件中配置3 參照開發包自帶的例子編寫Action類和配置struts.xml文件<struts><package name"demo" namespace"/hello/word"><action name"test" class"cn…

C#實現動態桌面背景圖片切換

問題描述&#xff1a;凝視桌面背景&#xff0c;突感如果桌面背景是變化的像win7一樣&#xff0c;該多有意思啊。鬧鐘瞬間產生一個念頭&#xff0c;用C#寫一個動態切換桌面背景的圖片。如何實現這個想法了&#xff0c;我思考了一會兒&#xff0c;想到了如下的一些需要解決的問題…

duration java_Java Duration類| withSeconds()方法與示例

duration java持續時間類withSeconds()方法 (Duration Class withSeconds() method) withSeconds() method is available in java.time package. withSeconds()方法在java.time包中可用。 withSeconds() method is used to represent this Duration with the given seconds. wi…

ffmpeg 命令畫中畫效果

畫中畫效果也是和圖片水印一樣使用movie配合overlay實現 使用ffplay預覽一下&#xff1a; ffplay -i cctvhttp.flv -vf “moviecctvhttp.flv[subm];[in][subm]overlayx20:y30[o ut]” -x 640 -y 480 &#xff08;可以看到是有兩層視頻的&#xff09; 用個不同的視頻再測試&…

實驗10 SQL Server 數據備份/恢復

實驗10 SQL Server 數據備份/恢復一、實驗目的 1.了解數據庫備份的過程和屬性設置&#xff1b; 2.掌握應用企業管理器備份和恢復數據庫&#xff1b; 3.掌握應用T-SQL備份和恢復數據庫&#xff1b; 4.掌握數據導入/導出的方法。 二、實驗要求 1.創建指定數據庫的備份. 2.恢復數…

指針和數組

數組的概念與指針的概念聯系非常解密。其實數組的標識相當于它的第一個元素的地址&#xff0c;就像一個指針相當于它所指向的第一個元素的地址&#xff0c;因此其實它們是同一個東西 int numbers [20];int * p;下面的賦值為合法的&#xff1a; p numbers; 這里指針p 和numbers…

程序集(初嘗,也是為插件程序準備)

拓展名是EXE或者DLL的.net可執行程序稱為程序集。 .net程序集與一般的EXE&#xff0c;DLL的區別在于&#xff0c;它包含有metadata。 私有程序集 位于應用程序的目錄下。共享程序集 必須有一個特殊的版本號&#xff0c;唯一的名稱&#xff0c;通常安裝在全局程序集緩存&#xf…

Java BigInteger類| 帶示例的shiftLeft()方法

BigInteger類shiftLeft()方法 (BigInteger Class shiftLeft() method) shiftLeft() method is available in java.math package. shiftLeft()方法在java.math包中可用。 shiftLeft() method is used to shift the given number of bits towards the left side in this BigInteg…

匯編語言-011(無符號乘法指令MUL、有符號乘法指令IMUL、對比MUL乘法指令與SHL移位方式、符號位擴展指令,CBW,CWD,CDQ、DIV 無符號除法指令、IDIV 有符號除法指令)

1:無符號乘法指令MUL .386 .model flat,stdcall.stack 4096 ExitProcess PROTO,dwExitCode:DWORD.data val1 WORD 2000h val2 WORD 0100h .code main PROC;8位乘法mov al,5h ;被乘數mov bl,10hmul bl ;AX 0050h ,CF,OF 0;16位乘法mov ax,val1mul val2 ;DX:AX 002000…

編寫一個程序,實現將存放在AX和DX中的32位數據循環右移二進制數的4位。(DX存放高字節內容,AX存放低字節內容)

編寫一個程序&#xff0c;實現將存放在AX和DX中的32位數據循環右移二進制數的4位。&#xff08;DX存放高字節內容&#xff0c;AX存放低字節內容&#xff09; P151 例4.9 匯編思路&#xff1a; AX右移四位后&#xff0c;使用BH接收AL的低四位數據&#xff0c;得到BH的八位數據…

[轉 scrum] 大型項目開發使用敏捷是否合適?不該問的問題

原文地址&#xff1a;http://www.scrumcn.com/agiledev/html/?167.html轉載于:https://www.cnblogs.com/cly84920/archive/2010/03/17/4426844.html

匯編語言-012(擴展加法指令ADC、帶借位減法指令SBB、執行加法后進行ASCII調整指令、AAS 、AAM、AAD 、DAA指令將和數轉成壓縮十進制格式)

1:ADC : 擴展加法指令ADC .386 .model flat,stdcall.stack 4096 ExitProcess PROTO,dwExitCode:DWORD.code main PROCmov dl,0mov al,0FFhadd al,0FFh ;ALFEhadc dl,0 ;DL:AL 01FEhmov edx,0mov eax,0FFFFFFFFhadd eax,0FFFFFFFFh ;EAX FFFFFFFEhadc edx,0 …

c#中textbox屬性_C#.Net中的TextBox.Visible屬性與示例

c#中textbox屬性Here we are demonstrating use of Visible property of TextBox Control. 在這里&#xff0c;我們演示了TextBox Control的Visible屬性的使用。 Visible property contains two values 可見屬性包含兩個值 True: Using this - textbox can be visible on par…

VS2010報表

http://technet.microsoft.com/zh-cn/library/dd220516.aspx轉載于:https://www.cnblogs.com/mingyongcheng/archive/2012/09/11/2679722.html

思維的領域特殊性

思維的領域特殊性 1971年&#xff0c;心理學家Danny Kahneman和Amos Tversky做了這樣一個實驗&#xff0c;他們問統計學教授一些不像統計學的統計學問題&#xff0c;其中一個大概如下&#xff1a;假設你生活的城市有兩家醫院&#xff0c;一家大一家小&#xff0c;某一天&#x…

匯編語言-013(DAS 、DAA與DAS、QWORD類型用SBB借位減法、編寫指令將AX符號擴展到EAX,不能使用CWD、用SHR和條件判斷指令將AL循環右移一位、SHLD、壓縮十進制轉換)

1&#xff1a;DAS : SUB或SBB在AL中生成二進制結果&#xff0c;DAS&#xff08;減法后的十進制調整&#xff09;轉壓縮十進制格式 .386 .model flat,stdcall.stack 4096 ExitProcess PROTO,dwExitCode:DWORD.code main PROC;計算85-48mov bl,48hmov al,85hsub al,bl ;AL3Dhd…

python程序執行時間_用于在Python中查找程序執行時間的程序

python程序執行時間The execution time of a program is defined as the time spent by the system to execute the task. As we all know any program takes some execution time but we dont know how much. So, dont worry, in this tutorial we will learn it by using the…

公約數和公倍數

描述 小明被一個問題給難住了&#xff0c;現在需要你幫幫忙。問題是&#xff1a;給出兩個正整數&#xff0c;求出它們的最大公約數和最小公倍數。 輸入 第一行輸入一個整數n&#xff08;0< n<10000)&#xff0c;表示有n組測試數據; 隨后的n行輸入兩個整數i,j&#xff08;…