java timezone_Java TimeZone getDefault()方法与示例

郭单鹗
2023-12-01

java timezone

TimeZone类的getDefault()方法 (TimeZone Class getDefault() method)

  • getDefault() method is available in java.util package.

    getDefault()方法在java.util包中可用。

  • getDefault() method is used to return the default time zone for this host.

    getDefault()方法用于返回此主机的默认时区。

  • getDefault() method is a static method, it is accessible with the class name and if we try to access the method with the class object then we will not get an error.

    getDefault()方法是静态方法,可以使用类名进行访问,如果尝试使用类对象访问该方法,则不会收到错误。

  • getDefault() method does not throw an exception at the time of getting the default time zone.

    getDefault()方法在获取默认时区时不会引发异常。

Syntax:

句法:

    public static TimeZone getDefault();

Parameter(s):

参数:

  • It does not accept any parameter.

    它不接受任何参数。

Return value:

返回值:

The return type of the method is TimeZone, it gets this default time zone.

该方法的返回类型为TimeZone ,它获取此默认时区。

Example:

例:

// Java program to demonstrate the example 
// of TimeZone getDefault() method of TimeZone 

import java.util.*;

public class GetDefaultOfTimeZone {
    public static void main(String args[]) {
        // Instantiate TimeZone object
        // By using getDefault() method is
        // to get the default time zone

        TimeZone tz = TimeZone.getDefault();
        System.out.println("TimeZone.getDefault(): " + tz);
    }
}

Output

输出量

TimeZone.getDefault(): sun.util.calendar.ZoneInfo[id="GMT",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]

翻译自: https://www.includehelp.com/java/timezone-getdefault-method-with-example.aspx

java timezone

 类似资料: