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());
热门推荐
8 留学生祝福语简短
10 送病人简短的祝福语
11 幼师离别祝福语老师简短
12 晚辈给长辈祝福语简短
13 康复儿童六一祝福语简短
14 妈妈的中考祝福语简短
15 生日贺卡祝福语简短创意
16 生日摆摊祝福语简短独特
17 过年红包祝福语简短霸气
18 生日祝福语送老公简短