博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java LocalDate类| plusWeeks()方法与示例
阅读量:2534 次
发布时间:2019-05-11

本文共 2610 字,大约阅读时间需要 8 分钟。

LocalDate类plusWeeks()方法 (LocalDate Class plusWeeks() method)

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

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

  • plusWeeks() method is used to add the given duration in weeks to this LocalDate and return the LocalDate.

    plusWeeks()方法用于将给定的持续时间(以周为单位)添加到此LocalDate并返回LocalDate。

  • plusWeeks() 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.

    plusWeeks()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • plusWeeks() method may throw an exception at the time of performing addition.

    plusWeeks()方法在执行加法时可能会引发异常。

    DateTimeException: This exception may throw when the calculated results exceed the length of this LocalDate.

    DateTimeException :当计算结果超过此LocalDate的长度时,可能引发此异常。

Syntax:

句法:

public LocalDate plusWeeks(long weeks_val);

Parameter(s):

参数:

  • long weeks_val – represents the weeks value to add to this LocalDate.

    long week_val –表示要添加到此LocalDate的周数。

Return value:

返回值:

The return type of this method is LocalDate, it returns the LocalDate that holds the value added the given weeks to this LocalDate.

此方法的返回类型为LocalDate ,它返回LocalDate,该LocalDate包含将给定周数添加到此LocalDate的值。

Example:

例:

// Java program to demonstrate the example // of plusWeeks(long weeks_val) method of LocalDateimport java.time.*;public class PlusWeeksOfLocalDate {
public static void main(String args[]) {
long weeks = 4; // 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 weeks 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("weeks to add: " + weeks); System.out.println(); // Here, this method adds the // given weeks to this date l_da1 // i.e. here we are adding 4 // weeks to the date l_da1 LocalDate plus_weeks = l_da1.plusWeeks(weeks); // Display plus_weeks System.out.println("l_da1.plusWeeks(weeks): " + plus_weeks); // Here, this method adds the // given weeks to this date l_da2 // i.e. here we are adding 4 // weeks to the date l_da2 plus_weeks = l_da2.plusWeeks(weeks); // Display plus_weeks System.out.println("l_da2.plusWeeks(weeks): " + plus_weeks); }}

Output

输出量

LocalDate l_da1,l_da2 : l_da1: 2007-04-04l_da2: 2008-02-06weeks to add: 4l_da1.plusWeeks(weeks): 2007-05-02l_da2.plusWeeks(weeks): 2008-03-05

翻译自:

转载地址:http://utvzd.baihongyu.com/

你可能感兴趣的文章
crash 收集
查看>>
507 LOJ 「LibreOJ NOI Round #1」接竹竿
查看>>
UI基础--烟花动画
查看>>
2018. 2.4 Java中集合嵌套集合的练习
查看>>
精通ASP.NET Web程序测试
查看>>
vue 根据不同属性 设置背景
查看>>
51Nod1601 完全图的最小生成树计数 Trie Prufer编码
查看>>
Codeforces 1110D. Jongmah 动态规划
查看>>
android驱动在win10系统上安装的心酸历程
查看>>
优雅的程序员
查看>>
oracle之三 自动任务调度
查看>>
Android dex分包方案
查看>>
ThreadLocal为什么要用WeakReference
查看>>
删除本地文件
查看>>
FOC实现概述
查看>>
base64编码的图片字节流存入html页面中的显示
查看>>
这个大学时代的博客不在维护了,请移步到我的新博客
查看>>
GUI学习之二十一——QSlider、QScroll、QDial学习总结
查看>>
nginx反向代理docker registry报”blob upload unknown"解决办法
查看>>
gethostbyname与sockaddr_in的完美组合
查看>>