当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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]


相关用法


注:本文由纯净天空筛选整理自Twinkl Bajaj大神的英文原创作品 SimpleTimeZone setStartYear() method in Java。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。