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

Java LocalDate类| minus()方法与示例相关推荐

  1. java annotation class,Java Class类 isAnnotation()方法及示例

    Class类isAnnotation()方法isAnnotation()方法在java.lang包中可用. isAnnotation()方法用于检查此Class对象是否表示注释类型. isAnnota ...

  2. java字符类型的返回值,Java字符类isWhitespace()方法及示例

    Character 类isWhitespace()法isWhitespace()方法在java.lang包中可用. isWhitespace()方法用于检查给定的char值是否为空格,但是它包含空格中 ...

  3. Java LocalDate类| parse()方法与示例

    LocalDate类parse()方法 (LocalDate Class parse() method) Syntax: 句法: public static LocalDate parse(CharS ...

  4. Java LocalDate类| minusYears()方法与示例

    LocalDate类minusYears()方法 (LocalDate Class minusYears() method) minusYears() method is available in j ...

  5. Java LocalDate类| 带示例的format()方法

    LocalDate类format()方法 (LocalDate Class format() method) format() method is available in java.time pac ...

  6. Java LocalDate类| toString()方法与示例

    LocalDate类toString()方法 (LocalDate Class toString() method) toString() method is available in java.ti ...

  7. Java LocalDate类| 带示例的compareTo()方法

    LocalDate类compareTo()方法 (LocalDate Class compareTo() method) compareTo() method is available in java ...

  8. Java LocalDate类| minusWeeks()方法与示例

    LocalDate类minusWeeks()方法 (LocalDate Class minusWeeks() method) minusWeeks() method is available in j ...

  9. Java LocalDate类| isSupported()方法与示例

    LocalDate类isSupported()方法 (LocalDate Class isSupported() method) Syntax: 句法: public boolean isSuppor ...

最新文章

  1. c语言英汉互译编程,用C语言编辑简单英汉互译词典.doc
  2. OC Foundation框架—字符串
  3. .net core实践系列之短信服务-为什么选择.net core(开篇)
  4. android 获取通讯录全选反选_Xamarin.Forms读取并展示Android和iOS通讯录 TerminalMACS客户端...
  5. Java高并发编程详解系列-ThreadAPI简单说明
  6. JavaTPoint Python 中文教程【翻译完成】
  7. python itertools模块_Python标准库:itertools模块
  8. 软件2班36人[扑林作]
  9. CAN总线网关是什么?
  10. 去除String首尾字符
  11. 功能对等四个原则_“功能对等”翻译理论--------奈达翻译理论体系的核心
  12. 一经开源就爆了!谷歌这个脚本工具注定要火
  13. 设计模式 外观模式 一键电影模式
  14. 软件设计模式与体系结构(上)
  15. 数据分析师常用的 Linux 命令总结
  16. 线性规划与网络流24题 太空飞行计划问题 (最小割及输出方案)
  17. Lorenz系统Lyapunov指数图
  18. canvas 水滴图、液体进度条、仿加速球、圆球水波图
  19. 设计自己的小游戏-飞机大战奖励篇
  20. 结构型 组合模式 Composite

热门文章

  1. java中匿名类的注意细节
  2. 下载国外网站资料需java_Java开发必知道的国外10大网站
  3. 一个android工程生成两个aar,android studio生成aar包并在其他工程引用aar包(示例代码)...
  4. java 泛型 加_Java泛型并将数字加在一起
  5. matlab meshgrid函数_matlab入门(三)图像可视化
  6. 传统的6d位姿估计fangfa1_李飞飞团队最新论文:基于anchor关键点的类别级物体6D位姿跟踪...
  7. TensorFlow构建二维数据拟合模型(1)
  8. JDK源码解析之 Java.lang.Double
  9. kodexplorer开源网盘php程序配置解析
  10. 小程序 - swiper除了左右切换还有上下滚动超出屏幕的内容