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