Instant truncatedTo(TemporalUnit unit)
描述 (Description)
java.time.Instant.truncatedTo(TemporalUnit unit)方法将截断的Instant的副本返回到指定的单元。
声明 (Declaration)
以下是java.time.Instant.truncatedTo(TemporalUnit unit)方法的声明。
public Instant truncatedTo(TemporalUnit unit)
参数 (Parameters)
unit - 要截断的单位,而不是null。
返回值 (Return Value)
基于此瞬间的瞬间,截断时间,而不是空。
异常 (Exceptions)
DateTimeException - 如果单位对于截断无效。
UnsupportedTemporalTypeException - 如果不支持该单位。
例子 (Example)
以下示例显示了java.time.Instant.truncatedTo(TemporalUnit unit)方法的用法。
package com.iowiki;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
public class InstantDemo {
public static void main(String[] args) {
Instant instant = Instant.parse("2014-12-03T10:15:30.00Z");
System.out.println(instant.truncatedTo(ChronoUnit.HOURS));
}
}
让我们编译并运行上面的程序,这将产生以下结果 -
2014-12-03T10:00:00Z