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

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

  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类| minus()方法与示例

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

  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. get the better of sb
  2. Thinkpad R400 a16驱动安装笔记
  3. 使用VS2019编写C语言程序,环境安装配置+代码调试
  4. 【MSTR产品】获取当前登陆用户的login_id
  5. 用HTML做软件UI用到的的一些技术
  6. 取得数组下标_《零基础C++入门教程》——(8)搞定二维数组与循环嵌套
  7. java 打印16进制数组_如何在Java中将字节数组转换为十六进制字符串?
  8. 程序员的算法课(15)-分治法获取文件中出现频次最高100词
  9. GARFIELD@10-21-2004
  10. html经过菜单变色移开恢复,h5学习笔记:transition菜单过渡变色
  11. 缺少链接库报错:ld: symbol(s) not found for architecture x86_64
  12. 以计算机基础知识做二十张ppt,计算机基础知识教程.ppt
  13. 面试风云录(03) - 与女大学生的网络对话(上)
  14. 【视频目标检测数据集收集】B站、YouTube等各大网站视频下载工具:Annie(现更名为lux)的下载与安装教程
  15. 中国省市区 json
  16. Geoserver:发布地图服务并修改样式
  17. 数据库设计案例(1)
  18. Nlite后期处理技术小结(第三次更新...全文完)(by bluewind)
  19. LoadLibraryA加载dll失败
  20. ActiveMQ 默认用户名和密码

热门文章

  1. nsct matlab,图像融合 NSCT算法 matlab
  2. android 布局防抖动,Android全屏返回布局抖动问题
  3. linux 秒数转时间格式,通过delphi将秒数转换成日期格式
  4. crio电压采集 labview_NI cDAQ917采集温度方法
  5. android config.mk,android编译分析之10—config.mk
  6. React antd Descriptions span属性无效问题
  7. async,await
  8. 学习 AngularJs 终于有点进步了。
  9. Scikit-Learn机器学习入门
  10. ASP 调用dll(VB)及封装dll实例