Java SimpleTimeZone setStartYear()方法

Java SimpleTimeZone setStartYear()方法

SimpleTimeZone类setStartYear() 方法用于设置日光节约时间的起始年份。

语法

public void setStartYear(int year)

参数: 该函数接受一个单一的参数 year ,指定夏令时的起始年份。

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

异常: 该函数没有抛出任何异常。

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

程序 1:

// 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]

程序2。

// 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]

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程