public static void main(String[] args) { TimeZone localTimezone = Calendar.getInstance().getTimeZone(); TimeZone gmtTimezone = TimeZone.getTimeZone("GMT"); TimeZone estTimezone = TimeZone.getTimeZone("EST"); Date time = new Date(); System.out.println("local time :" + DateUtil.getDateDisplayString(localTimezone, time)); System.out.println("GMT time :" + DateUtil.getDateDisplayString(gmtTimezone, time)); System.out.println("EST time :" + DateUtil.getDateDisplayString(estTimezone, time)); //Test next run time. Expects interval and schedule as arguments if (args.length == 2) { System.out.println("Next run time: " + DateUtil.getNextRunTime(IntervalType.getIntervalType(args[0]), args[1], "GMT", time).toString()); } }
private Date getNextScheduledTime(final long policyId, final Date currentTimestamp) { final SnapshotPolicyVO policy = _snapshotPolicyDao.findById(policyId); Date nextTimestamp = null; if (policy != null) { final short intervalType = policy.getInterval(); final IntervalType type = DateUtil.getIntervalType(intervalType); final String schedule = policy.getSchedule(); final String timezone = policy.getTimezone(); nextTimestamp = DateUtil.getNextRunTime(type, schedule, timezone, currentTimestamp); final String currentTime = DateUtil.displayDateInTimezone(DateUtil.GMT_TIMEZONE, currentTimestamp); final String nextScheduledTime = DateUtil.displayDateInTimezone(DateUtil.GMT_TIMEZONE, nextTimestamp); s_logger.debug("Current time is " + currentTime + ". NextScheduledTime of policyId " + policyId + " is " + nextScheduledTime); } return nextTimestamp; }
DateUtil.getNextRunTime(intvType, cmd.getSchedule(), timezoneId, null); } catch (Exception e) { throw new InvalidParameterValueException("Invalid schedule: " + cmd.getSchedule() + " for interval type: " + cmd.getIntervalType());