Java中SimpleTimeZone類的setStartRule(int startofMonth,int startofDay,int startofTime)方法用於將夏時製的特定開始規則設置為給定月份內的固定日期。
用法:
public void setStartRule(int startofMonth, int startofDay, int startofTime)
參數:該方法具有三個參數:
- startofMonth:這是整數類型,是指夏令時的開始月份。
- startofDay:這是整數類型,是指夏令時的開始日期。
- startofTime:這是整數類型,是指夏令時的開始時間。
返回值:該方法不返回任何值。
以下程序說明了Java中setStartRule()方法的用法:
範例1:
// Java code to demonstrate
// setStartRule() method
import java.util.*;
public class SimpleTimeZone_Demo {
public static void main(String[] args)
{
// Creating SimpleTimeZone object
SimpleTimeZone simtimeobj
= new SimpleTimeZone(100, "GMT");
// Displaying the Initial value
System.out.println(
"Initial value:" + simtimeobj);
// Setting an StartRule
simtimeobj.setStartRule(Calendar.APRIL,
28, 3600000);
// Displaying the New value
System.out.println(
"New value:" + simtimeobj);
}
}
輸出:
Initial value:java.util.SimpleTimeZone[id=GMT, offset=100, 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] New value:java.util.SimpleTimeZone[id=GMT, offset=100, dstSavings=3600000, useDaylight=false, startYear=0, startMode=1, startMonth=3, startDay=28, startDayOfWeek=0, startTime=3600000, startTimeMode=0, endMode=0, endMonth=0, endDay=0, endDayOfWeek=0, endTime=0, endTimeMode=0]
範例2:
// Java code to demonstrate
// setStartRule() method
import java.util.*;
public class SimpleTimeZone_Demo {
public static void main(String[] args)
{
// Creating SimpleTimeZone object
SimpleTimeZone simtimeobj
= new SimpleTimeZone(120, "GMT");
// Displaying the Initial value
System.out.println(
"Initial value:" + simtimeobj);
// Setting an StartRule
simtimeobj.setStartRule(Calendar.JANUARY,
15, 3600000);
// Displaying the New value
System.out.println(
"New value:" + simtimeobj);
}
}
輸出:
Initial value:java.util.SimpleTimeZone[id=GMT, offset=120, 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] New value:java.util.SimpleTimeZone[id=GMT, offset=120, dstSavings=3600000, useDaylight=false, startYear=0, startMode=1, startMonth=0, startDay=15, startDayOfWeek=0, startTime=3600000, startTimeMode=0, endMode=0, endMonth=0, endDay=0, endDayOfWeek=0, endTime=0, endTimeMode=0]
參考: https://docs.oracle.com/javase/10/docs/api/java/util/SimpleTimeZone.html#setStartRule(int,int,int)
相關用法
- Java SimpleTimeZone inDaylightTime()用法及代碼示例
- Java SimpleTimeZone getDSTSavings()用法及代碼示例
- Java SimpleTimeZone clone()用法及代碼示例
- Java SimpleTimeZone getRawOffset()用法及代碼示例
- Java SimpleTimeZone hashCode()用法及代碼示例
- Java SimpleTimeZone getOffset()用法及代碼示例
- Java SimpleTimeZone toString()用法及代碼示例
- Java SimpleTimeZone hasSameRules()用法及代碼示例
- Java SimpleTimeZone setDSTSavings()用法及代碼示例
- Java SimpleTimeZone equals()用法及代碼示例
- Java SimpleTimeZone setRawOffset()用法及代碼示例
- Java SimpleTimeZone setEndRule(int, int, int)用法及代碼示例
- Java SimpleTimeZone setStartYear()用法及代碼示例
- Java SimpleTimeZone useDaylightTime()用法及代碼示例
- Java Java.util.Collections.rotate()用法及代碼示例
注:本文由純淨天空篩選整理自Chinmoy Lenka大神的英文原創作品 SimpleTimeZone setStartRule(int, int, int) method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。