Java LocalDate类| minusDays()方法与示例
LocalDate类minusDays()方法 (LocalDate Class minusDays() method)minusDays() method is available in java.time package. minusDays()方法在java.time包中可用。 minusDays() method is used to subtract the given days f..
LocalDate类minusDays()方法 (LocalDate Class minusDays() method)
minusDays() method is available in java.time package.
minusDays()方法在java.time包中可用。
minusDays() method is used to subtract the given days from this LocalDate and return the LocalDate.
minusDays()方法用于从此LocalDate中减去给定的天数并返回LocalDate。
minusDays() 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.
minusDays()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
minusDays() method may throw an exception at the time of performing subtraction.
minusDays()方法在执行减法时可能会引发异常。
ArithmeticException: This exception may throw when the calculated result value exceeds the limit.
ArithmeticException :当计算结果值超过限制时,可能引发此异常。
Syntax:
句法:
public LocalDate minusDays(long day_val);
Parameter(s):
参数:
long day_val – represents the days to be subtracted from this LocalDate.
long day_val –表示要从此LocalDate中减去的天数。
Return value:
返回值:
The return type of this method is LocalDate, it returns the LocalDate that holds the value subtracted the given days from this LocalDate.
此方法的返回类型为LocalDate ,它返回LocalDate,该LocalDate保留从此LocalDate中减去给定天数的值。
Example:
例:
// Java program to demonstrate the example
// of minusDays(long day_val) method of LocalDate
import java.time.*;
public class MinusDaysOfLocalDate {
public static void main(String args[]) {
long days = 10;
// 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 days
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("days to subtract: " + days);
System.out.println();
// Here, this method subtracts the given
// days from this date l_da1 i.e. here we
// are subtracting 10 days from the date
// l_da1
LocalDate minus_days = l_da1.minusDays(days);
// Display minus_days
System.out.println("l_da1.minusDays(days): " + minus_days);
// Here, this method subtracts the given
// days from this date l_da2 i.e. here we
// are subtracting 10 days from the date
// l_da2
minus_days = l_da2.minusDays(days);
// Display minus_days
System.out.println("l_da2.minusDays(days): " + minus_days);
}
}
Output
输出量
LocalDate l_da1,l_da2 :
l_da1: 2007-04-04
l_da2: 2008-02-06
days to subtract: 10
l_da1.minusDays(days): 2007-03-25
l_da2.minusDays(days): 2008-01-27
翻译自: https://www.includehelp.com/java/localdate-minusdays-method-with-example.aspx
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)