Java中的Clock systemDefaultZone()方法
可以使用systemDefaultZone()Java中Clock类中的方法获得具有默认时区的当前时钟实例。此方法不需要任何参数,它会返回带有默认时区的当前时钟实例。
演示此的程序如下所示-
示例
import java.time.*;
public class Demo {
public static void main(String[] args) {
Clock c = Clock.systemDefaultZone();
Instant i = c.instant();
ZonedDateTime zdt = i.atZone(c.getZone());
System.out.println(zdt.toString());
}
}输出结果
2019-02-07T07:55:24.162Z[Etc/UTC]
现在让我们了解上面的程序。
使用方法获得具有默认时区的当前时钟实例systemDefaultZone()。然后使用方法打印ZonedDateTimetoString()。演示这的代码片段如下-
Clock c = Clock.systemDefaultZone(); Instant i = c.instant(); ZonedDateTime zdt = i.atZone(c.getZone()); System.out.println(zdt.toString());
热门推荐
10 朋友新年祝福语大全 简短
11 新年祝福语简短大方兔年
12 搬新家礼物祝福语简短
13 同学见面花束祝福语简短
14 五一假期祝福语幽默简短
15 离职欢送敬酒祝福语简短
16 对学弟的祝福语简短
17 考老师辞职祝福语简短
18 祝福语驱散霉运的话简短