Not to run code at 5:30 Morning in Summer and not to run code on 6:30 in winter.
In Java Code, Applied following
JavaScript
x
scheduler (30 mins)
if(time.equals(5:30))
///exit code
but now winter comes and we need not not run it at 6:30 AM
How to handle this use case for daylight saving areas?
Advertisement
Answer
You can use TimeZone
‘s inDaylightTime()
method to determine if day light saving is applied or not e.g.
JavaScript
if(TimeZone.getTimeZone("US/Alaska").inDaylightTime(new Date())){
// when daylight is true
}
else{
// Code when daylight saving is false
}
For machine’s default time zone, you can check like
JavaScript
TimeZone.getDefault().inDaylightTime(new Date())