本文整理汇总了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;
}
示例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;
}
示例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);
}
示例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);
}
示例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));
}
示例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);
}
}
}
示例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);
}
示例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;
}