Java 8 Clock getZone() 方法
在 Java 中,可以使用 Clock 类中的 getZone() 方法获取用于创建日期和时间的时区。此方法不需要参数,它返回所需时区。
演示这一点的程序如下所示 −
示例
import java.time.*;
public class Demo {
public static void main(String[] args) {
Clock c = Clock.systemDefaultZone();
ZoneId z = c.getZone();
System.out.println("The clock is: " + c);
System.out.println("The ZoneId is: " + z);
}
}输出
The clock is: SystemClock[Etc/UTC] The ZoneId is: Etc/UTC
现在让我们了解一下上述程序。
使用 getZone() 方法获取时区,然后显示此值。演示这一点的代码片段如下 −
Clock c = Clock.systemDefaultZone();
ZoneId z = c.getZone();
System.out.println("The clock is: " + c);
System.out.println("The ZoneId is: " + z);
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP