📌  相关文章
📜  Java中的 SimpleTimeZone setStartYear() 方法

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

Java中的 SimpleTimeZone setStartYear() 方法

SimpleTimeZone 类setStartYear()方法用于设置夏令时开始年份。

句法:

public void setStartYear(int year)

参数:该函数接受一个指定夏令时开始年份的参数year

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

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

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

方案一:

// program to demonstrate the
// function SimpleTimeZone.setStartYear()
  
import java.util.*;
  
public class GFG {
  
    public static void main(String[] args)
    {
        // create simple time zone object
        SimpleTimeZone obj
            = new SimpleTimeZone(500, "US");
  
        // printing
        System.out.println("SimpleTimeZone: "
                           + obj);
  
        // setting start year
        obj.setStartYear(2000);
  
        System.out.println("\nStartYear "
                           + "set to 2000\n");
  
        // printing the final value
        System.out.println("SimpleTimeZone: "
                           + obj);
    }
}
输出:
SimpleTimeZone: java.util.SimpleTimeZone[
    id=US,
    offset=500,
    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]

StartYear set to 2000

SimpleTimeZone: java.util.SimpleTimeZone[
    id=US,
    offset=500,
    dstSavings=3600000,
    useDaylight=false,
    startYear=2000,
    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 SimpleTimeZone.setStartYear()
  
import java.util.*;
  
public class GFG {
  
    public static void main(String[] args)
    {
        // create simple time zone object
        SimpleTimeZone obj
            = new SimpleTimeZone(620, "US");
  
        // printing
        System.out.println("SimpleTimeZone: "
                           + obj);
  
        // setting start year
        obj.setStartYear(2018);
  
        System.out.println("\nStartYear "
                           + "set to 2018\n");
  
        // printing the final value
        System.out.println("SimpleTimeZone: "
                           + obj);
    }
}
输出:
SimpleTimeZone: java.util.SimpleTimeZone[
    id=US,
    offset=620,
    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]

StartYear set to 2018

SimpleTimeZone: java.util.SimpleTimeZone[
    id=US,
    offset=620,
    dstSavings=3600000,
    useDaylight=false,
    startYear=2018,
    startMode=0,
    startMonth=0,
    startDay=0,
    startDayOfWeek=0,
    startTime=0,
    startTimeMode=0,
    endMode=0,
    endMonth=0,
    endDay=0,
    endDayOfWeek=0,
    endTime=0,
    endTimeMode=0]