org.joda.time.DateTime.plusMinutes()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(13.8k)|赞(0)|评价(0)|浏览(275)

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

DateTime.plusMinutes介绍

[英]Returns a copy of this datetime plus the specified number of minutes.

The calculation will add a duration equivalent to the number of minutes expressed in milliseconds.

The following three lines are identical in effect:

DateTime added = dt.plusMinutes(6); 
DateTime added = dt.plus(Period.minutes(6)); 
DateTime added = dt.withFieldAdded(DurationFieldType.minutes(), 6);

This datetime instance is immutable and unaffected by this method call.
[中]返回此datetime加上指定分钟数的副本。
计算将添加一个持续时间,该持续时间等于以毫秒表示的分钟数。
以下三行实际上是相同的:

DateTime added = dt.plusMinutes(6); 
DateTime added = dt.plus(Period.minutes(6)); 
DateTime added = dt.withFieldAdded(DurationFieldType.minutes(), 6);

此datetime实例是不可变的,不受此方法调用的影响。

代码示例

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

DateTime now = DateTime.now();
DateTime dateTime = now.plusMinutes(10);
Seconds seconds = Seconds.secondsBetween(now, dateTime);
System.out.println(seconds.getSeconds());

代码示例来源:origin: aws/aws-sdk-java

private Date getDefaultExpirationDate() {
  return new DateTime(clock.currentTimeMillis())
      .plusMinutes(SYNTHESIZE_SPEECH_DEFAULT_EXPIRATION_MINUTES)
      .toDate();
}

代码示例来源:origin: aws/aws-sdk-java

private Date getExpirationDate() {
  return new DateTime(clock.currentTimeMillis()).plusMinutes(DEFAULT_EXPIRATION_IN_MINUTES).toDate();
}

代码示例来源:origin: apache/incubator-gobblin

@Override
 public boolean shouldDeleteSnapshot(FileStatus snapshot, Trash trash) {
  DateTime snapshotTime = Trash.TRASH_SNAPSHOT_NAME_FORMATTER.parseDateTime(snapshot.getPath().getName());
  return snapshotTime.plusMinutes(this.retentionMinutes).isBeforeNow();
 }
}

代码示例来源:origin: dlew/joda-time-android

private void sampleDateTime() {
  List<String> text = new ArrayList<String>();
  DateTime now = DateTime.now();
  text.add("Now: " + now);
  text.add("Now + 30 minutes: " + now.plusMinutes(30));
  text.add("Now + 5 hours: " + now.plusHours(5));
  text.add("Now + 2 days: " + now.plusDays(2));
  addSample("DateTime", text);
}

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

private DateTime roundDate(final DateTime dateTime, final int minutes) {
  if (minutes < 1 || 60 % minutes != 0) {
    throw new IllegalArgumentException("minutes must be a factor of 60");
  }

  final DateTime hour = dateTime.hourOfDay().roundFloorCopy();
  final long millisSinceHour = new Duration(hour, dateTime).getMillis();
  final int roundedMinutes = ((int)Math.round(
    millisSinceHour / 60000.0 / minutes)) * minutes;
  return hour.plusMinutes(roundedMinutes);
}

代码示例来源:origin: dlew/joda-time-android

private void sampleDateRange() {
  List<String> text = new ArrayList<String>();
  DateTime start = DateTime.now();
  DateTime end = start.plusMinutes(30).plusHours(2).plusDays(56);
  text.add("Range: " + DateUtils.formatDateRange(this, start, end, 0));
  text.add("Range (with year): " + DateUtils.formatDateRange(this, start, end, DateUtils.FORMAT_SHOW_YEAR));
  text.add("Range (abbreviated): " + DateUtils.formatDateRange(this, start, end, DateUtils.FORMAT_ABBREV_ALL));
  text.add("Range (with time): " + DateUtils.formatDateRange(this, start, end, DateUtils.FORMAT_SHOW_TIME));
  addSample("DateUtils.formatDateRange()", text);
}

代码示例来源:origin: dlew/joda-time-android

private void sampleGetRelativeTimeSpanString() {
  List<String> text = new ArrayList<String>();
  DateTime now = DateTime.now();
  text.add("Short future: " + DateUtils.getRelativeTimeSpanString(this, now.plusMinutes(25)));
  text.add("Medium future: " + DateUtils.getRelativeTimeSpanString(this, now.plusHours(5)));
  text.add("Long future: " + DateUtils.getRelativeTimeSpanString(this, now.plusDays(3)));
  text.add("Short past: " + DateUtils.getRelativeTimeSpanString(this, now.minusMinutes(25)));
  text.add("Medium past: " + DateUtils.getRelativeTimeSpanString(this, now.minusHours(5)));
  text.add("Long past: " + DateUtils.getRelativeTimeSpanString(this, now.minusDays(3)));
  addSample("DateUtils.getRelativeTimeSpanString()", text);
}

代码示例来源:origin: dlew/joda-time-android

private void sampleGetRelativeDateTimeString() {
  List<String> text = new ArrayList<String>();
  DateTime now = DateTime.now();
  text.add("Short future: " + DateUtils.getRelativeDateTimeString(this, now.plusMinutes(25), null, 0));
  text.add("Medium future: " + DateUtils.getRelativeDateTimeString(this, now.plusHours(5), null, 0));
  text.add("Long future: " + DateUtils.getRelativeDateTimeString(this, now.plusDays(3), null, 0));
  text.add("Short past: " + DateUtils.getRelativeDateTimeString(this, now.minusMinutes(25), null, 0));
  text.add("Medium past: " + DateUtils.getRelativeDateTimeString(this, now.minusHours(5), null, 0));
  text.add("Long past: " + DateUtils.getRelativeDateTimeString(this, now.minusDays(3), null, 0));
  addSample("DateUtils.getRelativeDateTimeString()", text);
}

代码示例来源:origin: dlew/joda-time-android

private void sampleGetRelativeTimeSpanStringWithPreposition() {
  List<String> text = new ArrayList<String>();
  DateTime now = DateTime.now();
  text.add("Short future: " + DateUtils.getRelativeTimeSpanString(this, now.plusMinutes(25), true));
  text.add("Medium future: " + DateUtils.getRelativeTimeSpanString(this, now.plusHours(5), true));
  text.add("Long future: " + DateUtils.getRelativeTimeSpanString(this, now.plusDays(3), true));
  text.add("Short past: " + DateUtils.getRelativeTimeSpanString(this, now.minusMinutes(25), true));
  text.add("Medium past: " + DateUtils.getRelativeTimeSpanString(this, now.minusHours(5), true));
  text.add("Long past: " + DateUtils.getRelativeTimeSpanString(this, now.minusDays(3), true));
  addSample("DateUtils.getRelativeTimeSpanString() (with preposition)", text);
}

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

break;
case MINUTES:
  ret = new org.joda.time.Duration(dt, dt.plusMinutes((int) sampling.getValue())).getMillis();
  break;
case SECONDS:

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

/**
 * Test metric reporting methods, including InMemoryMetricEmitter methods
 */
@Test
public void managerEmitterHandlingTest() throws Exception {
 // metrics use System.currentTimeMillis, so that method should be the millis provider
 final DateTime aboutNow = new DateTime(System.currentTimeMillis());
 this.emitter.purgeAllData();
 final Date from = aboutNow.minusMinutes(1).toDate();
 this.metric.notifyManager();
 this.emitterWrapper.countDownLatch.await(10L, TimeUnit.SECONDS);
 final Date to = aboutNow.plusMinutes(1).toDate();
 final List<InMemoryHistoryNode> nodes = this.emitter.getMetrics("FakeMetric", from, to, false);
 assertEquals("Failed to report metric", 1, nodes.size());
 assertEquals("Failed to report metric", nodes.get(0).getValue(), 4);
}

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

@Test
public void shouldUpdateCompletedByTransitionIdAndStageState() throws Exception {
  assertThat(stage.getCompletedByTransitionId(), is(nullValue()));
  DateTime fiveMinsForNow = new DateTime().plusMinutes(5);
  complete(firstJob, fiveMinsForNow);
  complete(secondJob, fiveMinsForNow);
  JobStateTransition lastTransition = secondJob.getTransition(JobState.Completed);
  stage.calculateResult();
  assertThat(stage.getCompletedByTransitionId(), is(nextId));
  assertThat(stage.getState(), is(StageState.Passed));
}

代码示例来源:origin: apache/incubator-druid

queryStr = StringUtils.replace(queryStr, "%%TIMEBOUNDARY_RESPONSE_MINTIME%%", TIMESTAMP_FMT.print(dtFirst));
queryStr = StringUtils.replace(queryStr, "%%TIMESERIES_QUERY_START%%", INTERVAL_FMT.print(dtFirst));
queryStr = StringUtils.replace(queryStr, "%%TIMESERIES_QUERY_END%%", INTERVAL_FMT.print(dtLast.plusMinutes(2)));
queryStr = StringUtils.replace(queryStr, "%%TIMESERIES_RESPONSE_TIMESTAMP%%", TIMESTAMP_FMT.print(dtFirst));
queryStr = StringUtils.replace(queryStr, "%%POST_AG_REQUEST_START%%", INTERVAL_FMT.print(dtFirst));
queryStr = StringUtils.replace(queryStr, "%%POST_AG_REQUEST_END%%", INTERVAL_FMT.print(dtLast.plusMinutes(2)));
String postAgResponseTimestamp = TIMESTAMP_FMT.print(dtGroupBy.withSecondOfMinute(0));
queryStr = StringUtils.replace(queryStr, "%%POST_AG_RESPONSE_TIMESTAMP%%", postAgResponseTimestamp);

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

public static JobInstance buildEndingWithState(JobState endState, JobResult result, String jobConfig) {
  final JobInstance instance = new JobInstance(jobConfig);
  instance.setAgentUuid("1234");
  instance.setId(1L);
  instance.setIdentifier(defaultJobIdentifier(jobConfig));
  instance.setState(endState);
  instance.setTransitions(new JobStateTransitions());
  DateTime now = new DateTime();
  Date scheduledDate = now.minusMinutes(5).toDate();
  instance.setScheduledDate(scheduledDate);
  List<JobState> orderedStates = orderedBuildStates();
  DateTime stateDate = new DateTime(scheduledDate);
  for (JobState stateToCompareTo : orderedStates) {
    if (endState.compareTo(stateToCompareTo) >= 0) {
      instance.changeState(stateToCompareTo, stateDate.toDate());
      stateDate = stateDate.plusMinutes(1);
    }
  }
  if (endState.equals(JobState.Completed)) {
    instance.setResult(result);
  }
  return instance;
}

代码示例来源:origin: apache/incubator-druid

Interval interval = new Interval(t.minusMinutes(1), t.plusMinutes(1));

代码示例来源:origin: line/armeria

data.setNotOnOrAfter(DateTime.now().plusMinutes(1));
data.setRecipient(recipient);
conditions.setNotOnOrAfter(DateTime.now().plusMinutes(1));

代码示例来源:origin: apache/incubator-druid

@Test
 public void testCompareHour()
 {
  Result<Object> res = new Result<Object>(time, null);
  Result<Object> same = new Result<Object>(time.plusMinutes(55), null);
  Result<Object> greater = new Result<Object>(time.plusHours(1), null);
  Result<Object> less = new Result<Object>(time.minusHours(1), null);

  Granularity hour = Granularities.HOUR;
  Assert.assertEquals(ResultGranularTimestampComparator.create(hour, descending).compare(res, same), 0);
  Assert.assertEquals(ResultGranularTimestampComparator.create(hour, descending).compare(res, greater), descending ? 1 : -1);
  Assert.assertEquals(ResultGranularTimestampComparator.create(hour, descending).compare(res, less), descending ? -1 : 1);
 }
}

代码示例来源:origin: prestodb/presto

@Test
public void testAddFieldToTimestamp()
{
  assertFunction("date_add('millisecond', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusMillis(3), session));
  assertFunction("date_add('second', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusSeconds(3), session));
  assertFunction("date_add('minute', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusMinutes(3), session));
  assertFunction("date_add('hour', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusHours(3), session));
  assertFunction("date_add('hour', 23, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusHours(23), session));
  assertFunction("date_add('hour', -4, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.minusHours(4), session));
  assertFunction("date_add('hour', -23, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.minusHours(23), session));
  assertFunction("date_add('day', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusDays(3), session));
  assertFunction("date_add('week', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusWeeks(3), session));
  assertFunction("date_add('month', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusMonths(3), session));
  assertFunction("date_add('quarter', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusMonths(3 * 3), session));
  assertFunction("date_add('year', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusYears(3), session));
  assertFunction("date_add('millisecond', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusMillis(3)));
  assertFunction("date_add('second', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusSeconds(3)));
  assertFunction("date_add('minute', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusMinutes(3)));
  assertFunction("date_add('hour', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusHours(3)));
  assertFunction("date_add('day', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusDays(3)));
  assertFunction("date_add('week', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusWeeks(3)));
  assertFunction("date_add('month', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusMonths(3)));
  assertFunction("date_add('quarter', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusMonths(3 * 3)));
  assertFunction("date_add('year', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusYears(3)));
}

代码示例来源:origin: dlew/joda-time-android

assertEquals("in 30 seconds, 12:35", DateUtils.getRelativeDateTimeString(ctx, mNow.plusSeconds(30), null, 0));
assertEquals("30 seconds ago, 12:34", DateUtils.getRelativeDateTimeString(ctx, mNow.minusSeconds(30), null, 0));
assertEquals("in 30 minutes, 13:05", DateUtils.getRelativeDateTimeString(ctx, mNow.plusMinutes(30), null, 0));
assertEquals("30 minutes ago, 12:05", DateUtils.getRelativeDateTimeString(ctx, mNow.minusMinutes(30), null, 0));
assertEquals("in 3 hours, 15:35", DateUtils.getRelativeDateTimeString(ctx, mNow.plusHours(3), null, 0));

相关文章

DateTime类方法