当前位置: 首页>>代码示例>>Java>>正文


Java DateTime.minusHours方法代码示例

本文整理汇总了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;
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:8,代码来源:EmailComposerImpl.java

示例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;
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:33,代码来源:SystemInitializer.java


注:本文中的org.joda.time.DateTime.minusHours方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。