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

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

Syntax:

句法:

public LocalDate minus(TemporalAmount t_amt);
public LocalDate minus(long amt, TemporalUnit t_unit);

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

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

  • minus(TemporalAmount t_amt) method is used to subtract the given amount from this LocalDate and return the LocalDate.

    minus(TemporalAmount t_amt)方法用于從此LocalDate中減去給定的金額并返回LocalDate。

  • minus(long amt, TemporalUnit t_unit) method is used to subtract the given amount in the given unit from this LocalDate and return the LocalDate.

    minus(long amt,TemporalUnit t_unit)方法用于從此LocalDate中減去給定單位的給定數量,并返回LocalDate。

  • These methods may throw an exception at the time of performing subtraction.

    這些方法在執行減法時可能會引發異常。

    • ArithmeticException: This exception may throw when the calculated result exceeds the limit to represent this object.ArithmeticException :當計算結果超出表示此對象的限制時,可能引發此異常。
    • DateTimeException: This exception may throw when getting any error during subtraction.DateTimeException :在減法過程中遇到任何錯誤時,都可能引發此異常。
    • UnsupportedTemporalTypeException: This exception may throw when the given unit is unsupported.UnsupportedTemporalTypeException :當不支持給定單元時,可能引發此異常。
  • These are non-static methods and it is accessible with class objects and if we try to access these methods with the class name then we will get an error.

    這些是非靜態方法,可通過類對象訪問,如果嘗試使用類名訪問這些方法,則會收到錯誤消息。

Parameter(s):

參數:

  • In the first cases, minus(TemporalAmount t_amt),

    在第一種情況下,減號(TemporalAmount t_amt),

    • TemporalAmount t_amt – represents the amount to be subtracted from this LocalDate.
    • TemporalAmount t_amt –表示要從此LocalDate中減去的數量。
  • In the second cases, minus(long amt, TemporalUnit t_unit),

    在第二種情況下,減號(long amt,TemporalUnit t_unit),

    • long amt – represents the amount in units to be subtracted from this LocalDate.
    • long amt-表示要從此LocalDate中減去的金額(單位)。
    • TemporalUnit t_unit – represents the unit to measure the given amount.
    • TemporalUnit t_unit –代表測量給定數量的單位。

Return value:

返回值:

In both the cases, the return type of the method is LocalDate,

在這兩種情況下,方法的返回類型均為LocalDate 。

  • In the first case, it returns the LocalDate that holds the value subtracted the given amount from this LocalDate.

    在第一種情況下,它將返回LocalDate,該LocalDate保留從此LocalDate中減去給定值的值。

  • In the second case, it returns the LocalDate that holds the value subtracted the given amount in unit from this LocalDate.

    在第二種情況下,它將返回LocalDate,該LocalDate保留從此LocalDate中減去以單位為單位的給定值的值。

Example:

例:

// Java program to demonstrate the example 
// of minus() method of LocalDate
import java.time.*;
import java.time.temporal.*;
public class MinusOfLocalDate {
public static void main(String args[]) {
long amt = 4;
// Instantiates two LocalDate
LocalDate l_da1 = LocalDate.parse("2007-04-04");
LocalDate l_da2 = LocalDate.now();
// Instantiates a Period 
Period weeks = Period.ofWeeks(2);
// Display l_da1,l_da2 and amt
System.out.println("LocalDate l_da1 and l_da2: ");
System.out.println("l_da1: " + l_da1);
System.out.println("l_da2: " + l_da2);
System.out.println("amt to subtract: " + amt);
System.out.println();
// Here, this method subtracts the given
// amount from this LocalDate l_da1 i.e.
// here we are subtracting 2 weeks from
// this date l_da1
LocalDate l_date = l_da1.minus(weeks);
// Display l_date
System.out.println("l_da1.minus(weeks): " + l_date);
// Here, this method subtracts the given
// amount in the given unit from 
// this LocalDate l_da2 i.e. here
// we are subtracting the given amt
// (4) in the given unit (in months) 
// from this date l_da2
l_date = l_da2.minus(amt, ChronoUnit.MONTHS);
// Display l_date
System.out.println("l_da2.minus(amt,ChronoUnit.MONTHS): " + l_date);
}
}

Output

輸出量

LocalDate l_da1 and l_da2: 
l_da1: 2007-04-04
l_da2: 2020-06-03
amt to subtract: 4l_da1.minus(weeks): 2007-03-21
l_da2.minus(amt,ChronoUnit.MONTHS): 2020-02-03

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

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

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

相關文章

《Java EE 7精粹》—— 第3章 JSF 3.1 Facelets

本節書摘來異步社區《Java EE 7精粹》一書中的第2章,第2.1節,作者:【美】Arun Gupta,更多章節內容可以訪問云棲社區“異步社區”公眾號查看。 第3章 JSF JSF是基于Java的Web應用程序開發的服務器端用戶界面(UI&#xf…

mysql5批處理_轉關于mysql5.5 的批處理討論(轉載)

MySql的JDBC驅動不支持批量操作(已結)MySql連接的url中要加rewriteBatchedStatements參數,例如String connectionUrl"jdbc:mysql://192.168.1.100:3306/test?rewriteBatchedStatementstrue";還要保證mysql JDBC驅的版本。MySql的JDBC驅動的批量插入操作性…

Java Duration類| isZero()方法與示例

持續時間類isZero()方法 (Duration Class isZero() method) isZero() method is available in java.time package. isZero()方法在java.time包中可用。 isZero() method is used to check whether this Duration object holds the value of length is 0 or not. isZero()方法用…

《C#多線程編程實戰(原書第2版)》——3.2 在線程池中調用委托

本節書摘來自華章出版社《C#多線程編程實戰(原書第2版)》一書中的第3章,第3.2節,作者(美)易格恩阿格佛溫(Eugene Agafonov),黃博文 黃輝蘭 譯,更多章節內容可…

mysql語句數據庫_數據庫的Mysql語句

數據庫的mysql語句: 1.連接數據庫 mysql -u root -p2.顯示數據庫 show databases(db);3.選擇數據庫 use 數據庫名;4.顯示數據庫中的表 show tables;基本數據操作:增刪改查1.增 :insert into 表名(字段1,字段2…)values (值1,值2…);2.刪 :delete from 表名 where 條件;3.改 :up…

java clock計時_Java Clock類| systemUTC()方法與示例

java clock計時Clock Class systemUTC()方法 (Clock Class systemUTC() method) systemUTC() method is available in java.time package. systemUTC()方法在java.time包中可用。 systemUTC() method is used to get a Clock that implements the suitable system clock in the…

《Android 應用測試指南》——第2章,第2.4節包瀏覽器

本節書摘來自異步社區《Android 應用測試指南》一書中的第2章,第2.4節包瀏覽器,作者 【阿根廷】Diego Torres Milano(迭戈 D.),更多章節內容可以訪問云棲社區“異步社區”公眾號查看 2.4 包瀏覽器創建完前面提到的兩個…

操作系統系統調用_操作系統中的系統調用

操作系統系統調用系統調用簡介 (Introduction to System calls) The interface between the operating system and the user program is defined by the set of extended instruction that the operating system provides. These extended instructions are known as system ca…

java分數表示_表示Java分數的最佳方法?

小編典典碰巧的是不久前我寫了一個BigFraction類,用于解決Euler項目問題。它保留了BigInteger分子和分母,因此它將永遠不會溢出。但是,對于許多你永遠不會溢出的操作來說,這會有點慢。無論如何,請根據需要使用它。我一…

《OpenStack云計算實戰手冊(第2版)》——1.7 添加用戶

本節書摘來自異步社區《OpenStack云計算實戰手冊(第2版)》一書中的第1章,第1.7節,作者: 【英】Kevin Jackson , 【美】Cody Bunch 更多章節內容可以訪問云棲社區“異步社區”公眾號查看。 1.7 添加用戶 在OpenStack身份認證服務中…

開源軟件和自由軟件_自由和開源軟件的經濟學

開源軟件和自由軟件零邊際成本 (Zero Marginal Cost) At the core of the financial aspects of Free and Open Source is the zero negligible expense of merchandise in an environment that is digital. Right now, the rise of Free and Open Source speaks to an affirma…

java外部類_Java里什么叫內部類什么叫外部類

展開全部對普通類(沒有內部類的類)來說,62616964757a686964616fe78988e69d8331333337396234內部類和外部類都與他無關;對有內部類的類來說,它們就是其內部類的外部類,外部類是個相對的說法,其實就是有內部類的類。所以…

《精通Matlab數字圖像處理與識別》一6.2 傅立葉變換基礎知識

本節書摘來自異步社區《精通Matlab數字圖像處理與識別》一書中的第6章,第6.2節,作者 張錚 , 倪紅霞 , 苑春苗 , 楊立紅,更多章節內容可以訪問云棲社區“異步社區”公眾號查看 6.2 傅立葉變換基礎知識 精通Matlab數字圖像處理與識別要理解傅立…

多線程循環輸出abcc++_C ++循環| 查找輸出程序| 套裝5

多線程循環輸出abccProgram 1: 程序1&#xff1a; #include <iostream>using namespace std;int main(){int num 15673;int R1 0, R2 0;do {R1 num % 10;R2 R2 * 10 R1;num num / 10;} while (num > 0);cout << R2 << " ";return 0;}Ou…

java oql_深入理解java虛擬機(八):java內存分析工具-MAT和OQL

以下內容翻譯自MAT幫助文檔。一、Class HistogramClass Histogram shows the classes found in the snapshot, the number of objects for each class, the heap memory consumption of these objects, and the minimum retained size of the objects二、Dominator treeDomina…

《Python數據分析與挖掘實戰》一1.2 從餐飲服務到數據挖掘

本節書摘來自華章出版社《Python數據分析與挖掘實戰》一書中的第1章&#xff0c;第1.2節&#xff0c;作者 張良均 王路 譚立云 蘇劍林&#xff0c;更多章節內容可以訪問云棲社區“華章計算機”公眾號查看 1.2 從餐飲服務到數據挖掘 企業經營最大的目的就是盈利&#xff0c;而餐…

obj[]與obj._Ruby中帶有示例的Array.include?(obj)方法

obj[]與obj.Ruby Array.include&#xff1f;(obj)方法 (Ruby Array.include?(obj) Method) In the previous articles, we have seen how we can check whether two Array instances are identical or not with the help of <> operator, operator, and .eql? method?…

java javah_Java開發網 - 一個javah的問題

Posted by:jerry_xuPosted on:2006-03-13 15:39我在環境變量中已經設置了path為D:\Program Files\Java\jdk1.5.0_06&#xff0c;ClassPath設置為.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;class的路徑為&#xff1a;D:\JNItest\bin\jni\Hello.class &#xff0c;但是…

《Python面向對象編程指南》——2.7 __del__()方法

本節書摘來自異步社區《Python面向對象編程指南》一書中的第2章&#xff0c;第2.7節&#xff0c;作者&#xff3b;美&#xff3d;Steven F. Lott&#xff0c; 張心韜 蘭亮 譯&#xff0c;更多章節內容可以訪問云棲社區“異步社區”公眾號查看。 2.7 __del__()方法 __del__()方…

NullReferenceException C#中的異常

什么是NullReferenceException&#xff1f; (What is NullReferenceException?) NullReferenceException is an exception and it throws when the code is trying to access a reference that is not referencing to any object. If a reference variable/object is not refe…