Java中SimpleTimeZone類的inDaylightTime(Date)方法用於檢查和驗證給定日期是否在夏時製中。
用法:
public boolean inDaylightTime(Date date)
參數:該方法采用Date類型的一個參數date,這是要驗證的給定日期。
返回值:如果傳遞的日期相對於夏時製無效,則該方法返回布爾值True,否則返回布爾值False。
以下程序說明了Java中inDaylightTime()方法的用法:
示例1:
// Java code to demonstrate
// inDaylightTime() method
import java.util.*;
public class SimpleTimeZone_Demo {
public static void main(String[] args)
{
// Creating a time zone object
SimpleTimeZone simtimeobj
= new SimpleTimeZone(540, "GMT");
// Creating date object
Date dt = new Date();
// Verifying daylight
boolean bool_daylight
= simtimeobj.inDaylightTime(dt);
// Checking the value of day light
System.out.println("Is it in day"
+ " light saving time? "
+ bool_daylight);
}
}
輸出:
Is it in day light saving time? false
示例2:
// Java code to demonstrate
// inDaylightTime() method
import java.util.*;
public class SimpleTimeZone_Demo {
public static void main(String[] args)
{
// Creating a time zone object
SimpleTimeZone simtimeobj
= new SimpleTimeZone(400, "AUS");
// Creating a Calendar object
Calendar c1 = Calendar.getInstance();
// Set Month
// MONTH starts with 0 i.e.(0 - Jan)
c1.set(Calendar.MONTH, 00);
// Set Date
c1.set(Calendar.DATE, 30);
// Set Year
c1.set(Calendar.YEAR, 2019);
// Creating a date object
// with specified time.
Date dt = c1.getTime();
// Verifying daylight
boolean bool_daylight
= simtimeobj.inDaylightTime(dt);
// Checking the value of day light
System.out.println("Is it in day"
+ " light saving time? "
+ bool_daylight);
}
}
輸出:
Is it in day light saving time? false
相關用法
- Java TimeZone inDaylightTime()用法及代碼示例
- Java SimpleTimeZone getOffset()用法及代碼示例
- Java SimpleTimeZone getDSTSavings()用法及代碼示例
- Java SimpleTimeZone clone()用法及代碼示例
- Java SimpleTimeZone setDSTSavings()用法及代碼示例
- Java SimpleTimeZone hashCode()用法及代碼示例
- Java SimpleTimeZone getRawOffset()用法及代碼示例
- Java SimpleTimeZone setEndRule(int, int, int)用法及代碼示例
- Java SimpleTimeZone setStartRule(int, int, int)用法及代碼示例
- Java SimpleTimeZone toString()用法及代碼示例
- Java SimpleTimeZone hasSameRules()用法及代碼示例
- Java SimpleTimeZone equals()用法及代碼示例
- Java SimpleTimeZone setRawOffset()用法及代碼示例
- Java SimpleTimeZone setStartYear()用法及代碼示例
- Java SimpleTimeZone useDaylightTime()用法及代碼示例
注:本文由純淨天空篩選整理自Chinmoy Lenka大神的英文原創作品 SimpleTimeZone inDaylightTime() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。