I am trying to schedule a reminder email that has to be sent on first Tuesday of August and November. When I do that, the time of remainder email for November is changing from 10:00 AM to 11:00 AM (next run time). It fired correctly at 10:00 AM in August. This might be because of daylight saving. How should I prevent this from happening.
Code used for setting the Time Zone is:
java.util.TimeZone tz = TimeZone.getDefault();
tz = TimeZone.getTimeZone("US/Pacific");
When I inspect tz
using debugger, the value of it is:
sun.util.calendar.ZoneInfo[id="US/Pacific",offset=-28800000,dstSavings=3600000,useDaylight=true,transitions=185,lastRule=java.util.SimpleTimeZone[id=US/Pacific,offset=-28800000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]]
Code for creating CRON job is
org.quartz.TriggerBuilder builder = newTrigger().withSchedule(cronSchedule("0 0 10 ? AUG,NOV TUE#1").inTimeZone(tz));
I tried to find similar questions but for no luck. Should I use Calendar
class? Can you suggest any alternative for this.
If you want a fixed-offset time zone, just use SimpleTimeZone
:
TimeZone tz = new SimpleTimeZone(TimeUnit.SECONDS.toMillis(-420), "id");
See more on this question at Stackoverflow