本文整理匯總了Java中org.joda.time.DateTime.minusHours方法的典型用法代碼示例。如果您正苦於以下問題:Java DateTime.minusHours方法的具體用法?Java DateTime.minusHours怎麽用?Java DateTime.minusHours使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.joda.time.DateTime
的用法示例。
在下文中一共展示了DateTime.minusHours方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: adjustDST
import org.joda.time.DateTime; //導入方法依賴的package包/類
private static DateTime adjustDST(DateTime date, DateTimeZone dtz) {
DateTime dateTime = new DateTime(date, dtz);
if (!dtz.isStandardOffset(date.getMillis())) {
dateTime = dateTime.minusHours(1);
}
return dateTime;
}
示例2: secondsUntilNextMondayRun
import org.joda.time.DateTime; //導入方法依賴的package包/類
private int secondsUntilNextMondayRun() {
DateTime now = DateTime.now();
// Every Monday at 5AM UTC
int adjustedHours = 5;
if (!AppUtil.getDefaultTimeZone().isStandardOffset(now.getMillis())) {
// Have the run happen an hour earlier to take care of DST offset
adjustedHours -= 1;
}
DateTime nextRun = now.withHourOfDay(adjustedHours)
.withMinuteOfHour(0)
.withSecondOfMinute(0)
.withMillisOfSecond(0)
.plusWeeks(now.getDayOfWeek() == DateTimeConstants.MONDAY ? 0 : 1)
.withDayOfWeek(DateTimeConstants.MONDAY);
if (!nextRun.isAfter(now)) {
nextRun = nextRun.plusWeeks(1); // now is a Monday after scheduled run time -> postpone
}
// Case for: now there's no DST but by next run there will be.
if (adjustedHours == 5 && !AppUtil.getDefaultTimeZone().isStandardOffset(nextRun.getMillis())) {
nextRun = nextRun.minusHours(1);
}
// Case for: now there's DST but by next run there won't be
else if (adjustedHours != 5 && AppUtil.getDefaultTimeZone().isStandardOffset(nextRun.getMillis())) {
nextRun = nextRun.plusHours(1);
}
Logger.info("Scheduled next weekly report to be run at {}", nextRun.toString());
// Increase delay with one second so that this won't fire off before intended time. This may happen because of
// millisecond-level rounding issues and possibly cause resending of messages.
return Seconds.secondsBetween(now, nextRun).getSeconds() + 1;
}