ZonedDateTime类的getZone()方法用于从该ZonedDateTime获取时区。此方法返回ZoneId,例如“ Asia /Calcutta”。
用法:
public ZoneId getZone()
参数:此方法不带任何参数。
返回值:此方法返回代表时区的ZoneId。
以下示例程序旨在说明getZone()方法:
示例1:
// Java program to demonstrate
// ZonedDateTime.getZone() method
import java.time.*;
public class GFG {
public static void main(String[] args)
{
// create a ZonedDateTime object
ZonedDateTime zoneddatetime
= ZonedDateTime.parse(
"2018-12-06T19:21:12.123+05:30[Asia/Calcutta]");
// get zone
ZoneId value = zoneddatetime.getZone();
// print result
System.out.println("Time Zone:" + value);
}
}
输出:
Time Zone:Asia/Calcutta
示例2:
// Java program to demonstrate
// ZonedDateTime.getZone() method
import java.time.*;
public class GFG {
public static void main(String[] args)
{
// create a ZonedDateTime object
ZonedDateTime zoneddatetime
= ZonedDateTime.parse(
"1918-10-25T23:12:38.543+02:00[Europe/Paris]");
// get zone
ZoneId value = zoneddatetime.getZone();
// print result
System.out.println("Time Zone:" + value);
}
}
输出:
Time Zone:Europe/Paris