java.time.OffsetDateTime.plusMinutes()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(6.3k)|赞(0)|评价(0)|浏览(121)

本文整理了Java中java.time.OffsetDateTime.plusMinutes()方法的一些代码示例,展示了OffsetDateTime.plusMinutes()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OffsetDateTime.plusMinutes()方法的具体详情如下:
包路径:java.time.OffsetDateTime
类名称:OffsetDateTime
方法名:plusMinutes

OffsetDateTime.plusMinutes介绍

[英]Returns a copy of this OffsetDateTime with the specified period in minutes added.

This instance is immutable and unaffected by this method call.
[中]返回此OffsetDateTime的副本,并添加指定的时间段(以分钟为单位)。
此实例是不可变的,不受此方法调用的影响。

代码示例

代码示例来源:origin: kiegroup/jbpm

@Test
public void testParseRepeatableStartEndDateTime() {
  OffsetDateTime oneMinuteFromNow = OffsetDateTime.now().plusMinutes(1);
  OffsetDateTime twoMinutesFromNow = oneMinuteFromNow.plusMinutes(1);
  String oneMinuteFromNowFormatted = oneMinuteFromNow.format(DateTimeFormatter.ISO_DATE_TIME);
  String twoMinutesFromNowFormatted = twoMinutesFromNow.format(DateTimeFormatter.ISO_DATE_TIME);
  String isoString = "R5/" + oneMinuteFromNowFormatted  + "/" + twoMinutesFromNowFormatted;
  long[] parsedRepeatable = DateTimeUtils.parseRepeatableDateTime(isoString);
  assertEquals(5L, parsedRepeatable[0]);
  assertTrue("Parsed delay is bigger than " + MINUTE_IN_MILLISECONDS, parsedRepeatable[1] <= MINUTE_IN_MILLISECONDS);
  assertTrue("Parsed delay is too low! Expected value is between " + MINUTE_IN_MILLISECONDS + " and " + FIFTY_NINE_SECONDS_IN_MILLISECONDS + " but is " + parsedRepeatable[1], parsedRepeatable[1] > FIFTY_NINE_SECONDS_IN_MILLISECONDS);
  assertEquals("Parsed period should be one minute in milliseconds but is " + parsedRepeatable[2], MINUTE_IN_MILLISECONDS, parsedRepeatable[2]);
}

代码示例来源:origin: kiegroup/jbpm

@Test
public void testParseDateAsDuration() {
  OffsetDateTime oneMinuteFromNow = OffsetDateTime.now().plusMinutes(1);
  long parsedMilliseconds = DateTimeUtils.parseDateAsDuration(oneMinuteFromNow.format(DateTimeFormatter.ISO_DATE_TIME));
  assertTrue("Parsed date as duration is bigger than " + MINUTE_IN_MILLISECONDS, parsedMilliseconds <= MINUTE_IN_MILLISECONDS);
  assertTrue("Parsed date as duration is too low! Expected value is between " + MINUTE_IN_MILLISECONDS + " and " + FIFTY_NINE_SECONDS_IN_MILLISECONDS + " but is " + parsedMilliseconds, parsedMilliseconds > FIFTY_NINE_SECONDS_IN_MILLISECONDS);
}

代码示例来源:origin: kiegroup/jbpm

@Test
public void testParseRepeatablePeriodAndEndDateTime() {
  OffsetDateTime twoMinutesFromNow = OffsetDateTime.now().plusMinutes(2);
  String twoMinutesFromNowFormatted = twoMinutesFromNow.format(DateTimeFormatter.ISO_DATE_TIME);
  String isoString = "R5/PT1M/" + twoMinutesFromNowFormatted;
  long[] parsedRepeatable = DateTimeUtils.parseRepeatableDateTime(isoString);
  assertEquals(5L, parsedRepeatable[0]);
  assertTrue("Parsed delay is bigger than " + MINUTE_IN_MILLISECONDS, parsedRepeatable[1] <= MINUTE_IN_MILLISECONDS);
  assertTrue("Parsed delay is too low! Expected value is between " + MINUTE_IN_MILLISECONDS + " and " + FIFTY_NINE_SECONDS_IN_MILLISECONDS + " but is " + parsedRepeatable[1], parsedRepeatable[1] > FIFTY_NINE_SECONDS_IN_MILLISECONDS);
  assertEquals("Parsed period should be one minute in milliseconds but is " + parsedRepeatable[2], MINUTE_IN_MILLISECONDS, parsedRepeatable[2]);
}

代码示例来源:origin: kiegroup/jbpm

@Test
public void testParseRepeatableStartDateTimeAndPeriod() {
  OffsetDateTime oneMinuteFromNow = OffsetDateTime.now().plusMinutes(1);
  String oneMinuteFromNowFormatted = oneMinuteFromNow.format(DateTimeFormatter.ISO_DATE_TIME);
  String isoString = "R5/" + oneMinuteFromNowFormatted  + "/PT1M";
  long[] parsedRepeatable = DateTimeUtils.parseRepeatableDateTime(isoString);
  assertEquals(5L, parsedRepeatable[0]);
  assertTrue("Parsed delay is bigger than " + MINUTE_IN_MILLISECONDS, parsedRepeatable[1] <= MINUTE_IN_MILLISECONDS);
  assertTrue("Parsed delay is too low! Expected value is between " + MINUTE_IN_MILLISECONDS + " and " + FIFTY_NINE_SECONDS_IN_MILLISECONDS + " but is " + parsedRepeatable[1], parsedRepeatable[1] > FIFTY_NINE_SECONDS_IN_MILLISECONDS);
  assertEquals("Parsed period should be one minute in milliseconds but is " + parsedRepeatable[2], MINUTE_IN_MILLISECONDS, parsedRepeatable[2]);
}

代码示例来源:origin: com.github.seratch/java-time-backport

/**
 * Returns a copy of this {@code OffsetDateTime} with the specified period in minutes subtracted.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param minutes  the minutes to subtract, may be negative
 * @return an {@code OffsetDateTime} based on this date-time with the minutes subtracted, not null
 * @throws DateTimeException if the result exceeds the supported date range
 */
public OffsetDateTime minusMinutes(long minutes) {
  return (minutes == Long.MIN_VALUE ? plusMinutes(Long.MAX_VALUE).plusMinutes(1) : plusMinutes(-minutes));
}

代码示例来源:origin: stackoverflow.com

import java.time.OffsetDateTime;

...
OffsetDateTime dt = OffsetDateTime.now();
OffsetDateTime dt1 = dt.plusMinutes(5);

代码示例来源:origin: stackoverflow.com

Map<String, Object> claims = new HashMap<>();
OffsetDateTime now = OffsetDateTime.now(clock);
OffsetDateTime exp = now.plusMinutes(1);

代码示例来源:origin: org.openbase.bco/ontology.lib

/**
   * Method adds/subtracts time from the current dateTime.
   *
   * @param minutes are the minutes.
   * @param hours are the hours.
   * @param days are the days.
   * @param months are the months.
   * @param years are the years.
   * @return the changed dateTime as String.
   */
  public static String addTimeToCurrentDateTime(final int minutes, final int hours, final int days, final int months, final int years) {
    final OffsetDateTime now = OffsetDateTime.now();

    now.plusMinutes(minutes);
    now.plusHours(hours);
    now.plusDays(days);
    now.plusMonths(months);
    now.plusYears(years);

    return now.toString();
  }
}

代码示例来源:origin: FlareBot/FlareBot

@Override
public void onGuildJoin(GuildJoinEvent event) {
  if (event.getJDA().getStatus() == JDA.Status.CONNECTED &&
      event.getGuild().getSelfMember().getJoinDate().plusMinutes(2).isAfter(OffsetDateTime.now())) {
    Constants.getGuildLogChannel().sendMessage(new EmbedBuilder()
        .setColor(new Color(96, 230, 144))
        .setThumbnail(event.getGuild().getIconUrl())
        .setFooter(event.getGuild().getId(), event.getGuild().getIconUrl())
        .setAuthor(event.getGuild().getName(), null, event.getGuild().getIconUrl())
        .setTimestamp(event.getGuild().getSelfMember().getJoinDate())
        .setDescription("Guild Created: `" + event.getGuild().getName() + "` :smile: :heart:\n" +
            "Guild Owner: " + event.getGuild().getOwner().getUser().getName() + "\nGuild Members: " +
            event.getGuild().getMembers().size()).build()).queue();
  }
}

相关文章