java.time.OffsetDateTime.truncatedTo(TemporalUnit unit)
方法返回此OffsetDateTime
的副本,并截断时间。
声明
以下是java.time.OffsetDateTime.truncatedTo(TemporalUnit unit)
方法的声明。
public OffsetDateTime truncatedTo(TemporalUnit unit)
参数
unit
- 要截断的单位,而不是null
。
返回值
基于此日期时间截断时间的OffsetDateTime
,不为null
。
例外
DateTimeException
- 如果无法截断。UnsupportedTemporalTypeException
- 如果不支持该单位。
示例
以下示例显示了java.time.OffsetDateTime.truncatedTo(TemporalUnit unit)
方法的用法。
package com.zaixian;
import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;
public class OffsetDateTimeDemo {
public static void main(String[] args) {
OffsetDateTime date = OffsetDateTime.now();
System.out.println(date.truncatedTo(ChronoUnit.DAYS));
}
}
编译并运行上面的程序,这将产生以下结果 -
2017-03-21T00:00+05:30