📌  相关文章
📜  Java中的 SimpleTimeZone toString() 方法及示例

📅  最后修改于: 2022-05-13 01:55:25.654000             🧑  作者: Mango

Java中的 SimpleTimeZone toString() 方法及示例

SimpleTimeZone 类toString()方法用于获取该时区的字符串表示形式。

句法:

public String toString()

参数:该函数不接受任何参数。

返回值:该方法没有返回值。

异常:该函数不抛出任何异常。

下面的程序演示了上述函数:

方案一:

// program to demonstrate the
// function java.util.SimpleTimeZone.toString()
import java.util.*;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // create simple time zone object
        SimpleTimeZone obj
            = new SimpleTimeZone(700, "US");
  
        // get string value of time zone
        // and print the result
        System.out.println("String value is = "
                           + obj.toString());
    }
}
输出:
String value is =  java.util.SimpleTimeZone[
    id=US,
    offset=700,
    dstSavings=3600000,
    useDaylight=false,
    startYear=0,
    startMode=0,
    startMonth=0,
    startDay=0,
    startDayOfWeek=0,
    startTime=0,
    startTimeMode=0,
    endMode=0,
    endMonth=0,
    endDay=0,
    endDayOfWeek=0,
    endTime=0,
    endTimeMode=0]

方案二:

// program to demonstrate the
// function java.util.SimpleTimeZone.toString()
import java.util.*;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // create simple time zone object
        SimpleTimeZone obj
            = new SimpleTimeZone(800, "US");
  
        // get string value of time zone
        // and print the result
        System.out.println("String value is = "
                           + obj.toString());
    }
}
输出:
String value is =  java.util.SimpleTimeZone[
    id=US,
    offset=800,
    dstSavings=3600000,
    useDaylight=false,
    startYear=0,
    startMode=0,
    startMonth=0,
    startDay=0,
    startDayOfWeek=0,
    startTime=0,
    startTimeMode=0,
    endMode=0,
    endMonth=0,
    endDay=0,
    endDayOfWeek=0,
    endTime=0,
    endTimeMode=0]