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.mzph.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…