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


Java DateTime.plusMinutes方法代码示例

本文整理汇总了Java中org.joda.time.DateTime.plusMinutes方法的典型用法代码示例。如果您正苦于以下问题:Java DateTime.plusMinutes方法的具体用法?Java DateTime.plusMinutes怎么用?Java DateTime.plusMinutes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.joda.time.DateTime的用法示例。


在下文中一共展示了DateTime.plusMinutes方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getTimePointBetweenDates

import org.joda.time.DateTime; //导入方法依赖的package包/类
/**
 * 计算两个时间段间隔里面按照固定间隔返回时间点集合
 * <p/>
 * 这里会 startDate 到 endDate 最后endDate如果相等会算入集合
 * 如:[2016-10-20 12:00:00.000 -2016-10-20 13:00:00.000,'yyyy-MM-dd HH:mm',30]
 * 返回:["2016-10-20 12:00","2016-10-20 12:30","2016-10-20 13:00"]
 * @param date1
 * @param date2
 * @param minutesSplit 间隔多少分
 * @param pattern
 * @return
 */
public static List<String> getTimePointBetweenDates(@NotNull Date date1, @NotNull Date date2, @NotNull String pattern, int minutesSplit) {
    Objects.requireNonNull(date1, "startDate must not null");
    Objects.requireNonNull(date2, "endDate must not null");
    Objects.requireNonNull(pattern, "pattern must not null");
    Date startDate = date1;
    Date endDate = date2;
    //调整顺序
    if (date1.after(date2)) {
        startDate = date2;
        endDate = date1;
    }
    DateTime startDateTime = new DateTime(startDate);
    DateTime endDateTime = new DateTime(endDate);
    List<String> points = new ArrayList<>();
    while (startDateTime.isBefore(endDateTime.getMillis()) || startDateTime.getMillis() == endDateTime.getMillis()) {
        points.add(DateFormatter.format(startDateTime.getMillis(), pattern));
        startDateTime = startDateTime.plusMinutes(minutesSplit);
    }
    return points;
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:33,代码来源:DateCalculator.java

示例2: gatherSuitableSlots

import org.joda.time.DateTime; //导入方法依赖的package包/类
protected Collection<Interval> gatherSuitableSlots(ExamRoom room, LocalDate date, Integer examDuration) {
    Collection<Interval> examSlots = new ArrayList<>();
    // Resolve the opening hours for room and day
    List<ExamRoom.OpeningHours> openingHours = room.getWorkingHoursForDate(date);
    if (!openingHours.isEmpty()) {
        // Get suitable slots based on exam duration
        for (Interval slot : allSlots(openingHours, room, date)) {
            DateTime beginning = slot.getStart();
            DateTime openUntil = getEndOfOpeningHours(beginning, openingHours);
            if (!beginning.plusMinutes(examDuration).isAfter(openUntil)) {
                DateTime end = beginning.plusMinutes(examDuration);
                examSlots.add(new Interval(beginning, end));
            }
        }
    }
    return examSlots;
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:18,代码来源:CalendarController.java

示例3: testTimePlus

import org.joda.time.DateTime; //导入方法依赖的package包/类
/**
 * 时间加减操作,plus 负数时是向前推移
 */
@Test
public void testTimePlus() {
    // 获取当前时间
    DateTime dt = new DateTime();
    String currentTime = dt.toString("yyyy-MM-dd HH:mm:ss");
    System.out.println("currentTime: " + currentTime);

    // 相对当前时间 向后5天,5天后
    DateTime plus5Days = dt.plusDays(5);
    String plus5DaysStr = plus5Days.toString("yyyy-MM-dd HH:mm:ss");
    System.out.println("plus 5 days: " + plus5DaysStr);

    // 相对当前时间 向后5个小时,5小时后
    DateTime plus5Hours = dt.plusHours(5);
    String plus5HoursStr = plus5Hours.toString("yyyy-MM-dd HH:mm:ss");
    System.out.println("plus 5 hours: " + plus5HoursStr);

    // 相对当前时间,向后5分钟,5分钟后
    DateTime plus5Minutes = dt.plusMinutes(5);
    String plus5MinutesStr = plus5Minutes.toString("yyyy-MM-dd HH:mm:ss");
    System.out.println("plus 5 minutes: " + plus5MinutesStr);

    // 相对当前时间,向前5年,5年前
    DateTime plus5Years = dt.plusYears(-5);
    String plus5YearsStr = plus5Years.toString("yyyy-MM-dd HH:mm:ss");
    System.out.println("5 years ago: " + plus5YearsStr);

    // 相对当前时间,向前5个月
    DateTime plusMonths = dt.plusMonths(-5);
    String plusMonthsStr = plusMonths.toString("yyyy-MM-dd HH:mm:ss");
    System.out.println("5 month ago: " + plusMonthsStr);
}
 
开发者ID:cbooy,项目名称:cakes,代码行数:36,代码来源:JodaTimeDemo1.java

示例4: getUpcomingExternalReservation

import org.joda.time.DateTime; //导入方法依赖的package包/类
private Reservation getUpcomingExternalReservation(String eppn) {
    DateTime now = AppUtil.adjustDST(new DateTime());
    int lookAheadMinutes = Minutes.minutesBetween(now, now.plusDays(1).withMillisOfDay(0)).getMinutes();
    DateTime future = now.plusMinutes(lookAheadMinutes);
    List<Reservation> reservations = Ebean.find(Reservation.class).where()
            .eq("externalUserRef", eppn)
            .isNotNull("externalRef")
            .le("startAt", future)
            .gt("endAt", now)
            .orderBy("startAt")
            .findList();
    return reservations.isEmpty() ? null : reservations.get(0);
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:14,代码来源:SessionController.java

示例5: getNextEnrolment

import org.joda.time.DateTime; //导入方法依赖的package包/类
private Optional<ExamEnrolment> getNextEnrolment(Long userId, int minutesToFuture) {
    DateTime now = AppUtil.adjustDST(new DateTime());
    DateTime future = now.plusMinutes(minutesToFuture);
    List<ExamEnrolment> results = Ebean.find(ExamEnrolment.class)
            .fetch("reservation")
            .fetch("reservation.machine")
            .fetch("reservation.machine.room")
            .fetch("exam")
            .fetch("externalExam")
            .where()
            .eq("user.id", userId)
            .disjunction()
            .eq("exam.state", Exam.State.PUBLISHED)
            .eq("exam.state", Exam.State.STUDENT_STARTED)
            .jsonEqualTo("externalExam.content", "state", Exam.State.PUBLISHED.toString())
            .jsonEqualTo("externalExam.content", "state", Exam.State.STUDENT_STARTED.toString())
            .endJunction()
            .le("reservation.startAt", future)
            .gt("reservation.endAt", now)
            .isNotNull("reservation.machine")
            .orderBy("reservation.startAt")
            .findList();
    if (results.isEmpty()) {
        return Optional.empty();
    }
    return Optional.of(results.get(0));
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:28,代码来源:SystemRequestHandler.java

示例6: markEnded

import org.joda.time.DateTime; //导入方法依赖的package包/类
private void markEnded(List<ExamParticipation> participations) {
    for (ExamParticipation participation : participations) {
        Exam exam = participation.getExam();
        Reservation reservation = participation.getReservation();
        DateTime reservationStart = new DateTime(reservation.getStartAt());
        DateTime participationTimeLimit = reservationStart.plusMinutes(exam.getDuration());
        DateTime now = AppUtil.adjustDST(DateTime.now(), reservation.getMachine().getRoom());
        if (participationTimeLimit.isBefore(now)) {
            participation.setEnded(now);
            participation.setDuration(
                    new DateTime(participation.getEnded().getMillis() - participation.getStarted().getMillis()));

            GeneralSettings settings = SettingsController.getOrCreateSettings("review_deadline", null, "14");
            int deadlineDays = Integer.parseInt(settings.getValue());
            DateTime deadline = new DateTime(participation.getEnded()).plusDays(deadlineDays);
            participation.setDeadline(deadline);

            participation.save();
            Logger.info("{}: ... setting exam {} state to REVIEW", getClass().getCanonicalName(), exam.getId());
            exam.setState(Exam.State.REVIEW);
            exam.save();
            if (exam.isPrivate()) {
                // Notify teachers
                Set<User> recipients = new HashSet<>();
                recipients.addAll(exam.getParent().getExamOwners());
                recipients.addAll(exam.getExamInspections().stream().map(
                        ExamInspection::getUser).collect(Collectors.toSet()));
                AppUtil.notifyPrivateExamEnded(recipients, exam, composer);
            }
        } else {
            Logger.info("{}: ... exam {} is ongoing until {}", getClass().getCanonicalName(), exam.getId(),
                    participationTimeLimit);
        }
    }
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:36,代码来源:ExamAutoSaverActor.java

示例7: setCacheScanSoftIfHit

import org.joda.time.DateTime; //导入方法依赖的package包/类
@Override
public void setCacheScanSoftIfHit(HttpServletResponse resp) {
    DateTime now = new DateTime();

    long keepMinute = now.getMillis() / interval * interval;
    DateTime keepMinuteDateTime = new DateTime(keepMinute);
    int min = keepMinuteDateTime.getMinuteOfHour();
    min = getPrevIntervalMinute(min);
    DateTime lastModified = keepMinuteDateTime.minuteOfHour().setCopy(min);
    resp.setHeader("Last-Modified", toGMT(lastModified));
    DateTime expires = now.plusMinutes(expiresMinuteForScansoftIfHit);
    resp.setHeader("Expires", toGMT(expires));
    resp.setHeader("Cache-Control", maxAgeIfHit);
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:15,代码来源:CDNCacheImpl.java

示例8: doCommand

import org.joda.time.DateTime; //导入方法依赖的package包/类
@Override
public boolean doCommand(MessageReceivedEvent message, BotContext context, String content) throws DiscordException {
    try {
        DateTime date = null;
        String reminder = null;
        Matcher m = PATTERN.matcher(content);
        if (m.find()) {
            date = FORMATTER.parseDateTime(String.format("%s %s", m.group(1), m.group(2)));
            reminder = m.group(3);
            if (DateTime.now().isAfter(date)) {
                messageService.onError(message.getChannel(), "discord.command.remind.error.future");
                return fail(message);
            }
        }

        String keyWord = messageService.getMessage("discord.command.remind.keyWord");
        m = Pattern.compile(String.format(RELATIVE_PATTERN_FORMAT, keyWord)).matcher(content);
        if (m.find()) {
            Long millis = SEQUENCE_PARSER.parse(m.group(1));
            reminder = m.group(2);
            if (millis != null && StringUtils.isNotEmpty(reminder)) {
                date = DateTime.now().plus(millis);
            }
        }

        if (date != null && reminder != null) {
            createReminder(message.getChannel(), message.getMember(), reminder, date.toDate());
            return ok(message, "discord.command.remind.done");
        }
    } catch (IllegalArgumentException e) {
        // fall down
    }

    String prefix = context.getConfig() != null ? context.getConfig().getPrefix() : configService.getDefaultPrefix();

    DateTime current = DateTime.now();
    current = current.plusMinutes(1);
    EmbedBuilder builder = messageService.getBaseEmbed();
    builder.setTitle(messageService.getMessage("discord.command.remind.help.title"));
    builder.addField(
            messageService.getMessage("discord.command.remind.help.field1.title"),
            messageService.getMessage("discord.command.remind.help.field1.value", prefix, FORMATTER.print(current)), false);
    builder.addField(
            messageService.getMessage("discord.command.remind.help.field2.title"),
            messageService.getMessage("discord.command.remind.help.field2.value", prefix), false);
    messageService.sendMessageSilent(message.getChannel()::sendMessage, builder.build());
    return false;
}
 
开发者ID:GoldRenard,项目名称:JuniperBotJ,代码行数:49,代码来源:RemindCommand.java


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