Java中的即时truncatedTo()方法
可以使用truncatedTo()JavaInstant类中的方法获得不可变的截断的Instant。此方法需要一个参数,即TemporalUnit,直到Instant被截断为止,并且它返回不可变的被截断的Instant。
演示此的程序如下所示-
示例
import java.time.*;
import java.time.temporal.ChronoUnit;
public class Demo {
public static void main(String[] args) {
Instant instant = Instant.now();
System.out.println("The current instant is: " + instant);
Instant truncatedInstant = instant.truncatedTo(ChronoUnit.MINUTES);
System.out.println("The truncated instant is: " + truncatedInstant);
}
}输出结果
The current instant is: 2019-02-13T08:49:09.188Z The truncated instant is: 2019-02-13T08:49:00Z
现在让我们了解上面的程序。
首先显示当前时刻。然后使用该truncatedTo()方法获得不可变的截断的Instant并显示出来。演示这的代码片段如下-
Instant instant = Instant.now();
System.out.println("The current instant is: " + instant);
Instant truncatedInstant = instant.truncatedTo(ChronoUnit.MINUTES);
System.out.println("The truncated instant is: " + truncatedInstant);热门推荐
10 小侄过生日祝福语简短
11 小店营业的祝福语简短
12 担任老师的祝福语简短
13 饮料吧台祝福语简短大气
14 公司新春搞笑祝福语简短
15 高情商敬酒祝福语简短
16 婚礼祝福语新郎妹妹简短
17 教师答辩通过祝福语简短
18 生女孩红包简短祝福语