目录

long until(Temporal endExclusive, TemporalUnit unit)

描述 (Description)

java.time.LocalDate.until(Temporal endExclusive, TemporalUnit unit)方法根据指定的单位计算到另一个日期的时间量。

声明 (Declaration)

以下是java.time.LocalDate.until(Temporal endExclusive, TemporalUnit unit)方法的声明。

public long until(Temporal endExclusive, TemporalUnit unit)

参数 (Parameters)

  • endDateExclusive - 结束日期,独占,转换为LocalDate,而不是null。

  • unit - 衡量金额的单位,而不是空。

返回值 (Return Value)

此日期和结束日期之间的时间量。

异常 (Exceptions)

  • DateTimeException - 如果无法计算金额,或者结束时间不能转换为LocalDate。

  • UnsupportedTemporalTypeException - 如果不支持该单位。

  • ArithmeticException - 如果发生数字溢出。

例子 (Example)

以下示例显示了java.time.LocalDate.until(Temporal endExclusive,TemporalUnit unit)方法的用法。

package com.iowiki;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
public class LocalDateDemo {
   public static void main(String[] args) {
	  LocalDate date = LocalDate.parse("2017-01-03");
      LocalDate date1 = LocalDate.now();
      System.out.println(date.until(date1, ChronoUnit.DAYS));  
   }
}

让我们编译并运行上面的程序,这将产生以下结果 -

343
↑回到顶部↑
WIKI教程 @2018