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

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

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

DateTime.minusSeconds介绍

[英]Returns a copy of this datetime minus the specified number of seconds.

The calculation will subtract a duration equivalent to the number of seconds expressed in milliseconds.

The following three lines are identical in effect:

DateTime subtracted = dt.minusSeconds(6); 
DateTime subtracted = dt.minus(Period.seconds(6)); 
DateTime subtracted = dt.withFieldAdded(DurationFieldType.seconds(), -6);

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

DateTime subtracted = dt.minusSeconds(6); 
DateTime subtracted = dt.minus(Period.seconds(6)); 
DateTime subtracted = dt.withFieldAdded(DurationFieldType.seconds(), -6);

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

代码示例

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

DateTime deltaTime = getCurrentTime(timeZone).minusSeconds(limitDelta);
DateTime previousTime =
  Utils.toDateTime(Utils.dateTimeToString(deltaTime, format, timeZone), format, timeZone).plusSeconds(seconds);

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

dtGroupBy = dt;
} else if (i == 18) { // use a time 6 seconds ago so it will be out of order
 dt = dt.minusSeconds(6);

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

dtGroupBy = dt;
} else if (i == 18) { // use a time 6 seconds ago so it will be out of order
 dt = dt.minusSeconds(6);

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

assertEquals("1 second ago", DateUtils.getRelativeTimeSpanString(ctx, DateTime.now().minusSeconds(1)));
assertEquals("30 seconds ago", DateUtils.getRelativeTimeSpanString(ctx, DateTime.now().minusSeconds(30)));
assertEquals("in 1 sec", DateUtils.getRelativeTimeSpanString(ctx, DateTime.now().plusSeconds(1),
  DateUtils.FORMAT_ABBREV_RELATIVE));
assertEquals("in 30 secs", DateUtils.getRelativeTimeSpanString(ctx, DateTime.now().plusSeconds(30),
  DateUtils.FORMAT_ABBREV_RELATIVE));
assertEquals("1 sec ago", DateUtils.getRelativeTimeSpanString(ctx, DateTime.now().minusSeconds(1),
  DateUtils.FORMAT_ABBREV_RELATIVE));
assertEquals("30 secs ago", DateUtils.getRelativeTimeSpanString(ctx, DateTime.now().minusSeconds(30),
  DateUtils.FORMAT_ABBREV_RELATIVE));

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

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));
  DateUtils.getRelativeDateTimeString(ctx, mNow.plusSeconds(30), null, DateUtils.FORMAT_ABBREV_RELATIVE));
assertEquals("30 secs ago, 12:34",
  DateUtils.getRelativeDateTimeString(ctx, mNow.minusSeconds(30), null, DateUtils.FORMAT_ABBREV_RELATIVE));

代码示例来源:origin: rackerlabs/blueflood

@Test
public void testRangeOnlySearch() throws Exception {
  Map<String, List<String>> query = new HashMap<>();
  final int eventCountToCapture = TENANT_RANGE_EVENTS_NUM / 2;
  final int secondsDelta = 10;
  DateTime fromDateTime = new DateTime().minusSeconds(RANGE_STEP_IN_SECONDS * eventCountToCapture - secondsDelta);
  query.put(Event.fromParameterName, Arrays.asList(Long.toString(fromDateTime.getMillis())));
  List<Map<String, Object>> results = searchIO.search(TENANT_RANGE, query);
  Assert.assertEquals(eventCountToCapture, results.size());
  DateTime untilDateTime = new DateTime().minusSeconds(RANGE_STEP_IN_SECONDS * eventCountToCapture - secondsDelta);
  query.clear();
  query.put(Event.untilParameterName, Arrays.asList(Long.toString(untilDateTime.getMillis())));
  results = searchIO.search(TENANT_RANGE, query);
  Assert.assertEquals(eventCountToCapture, results.size());
  query.clear();
  fromDateTime = new DateTime().minusSeconds(RANGE_STEP_IN_SECONDS * 2 - secondsDelta);
  untilDateTime = new DateTime().minusSeconds(RANGE_STEP_IN_SECONDS - secondsDelta);
  query.put(Event.fromParameterName, Arrays.asList(Long.toString(fromDateTime.getMillis())));
  query.put(Event.untilParameterName, Arrays.asList(Long.toString(untilDateTime.getMillis())));
  results = searchIO.search(TENANT_RANGE, query);
  Assert.assertEquals(1, results.size());
}

代码示例来源:origin: rackerlabs/blueflood

private static void createRangeEvents(String tenant, int eventCount, int stepInSeconds) throws Exception {
  Map<String, Object> eventMap;
  DateTime date = new DateTime();
  for (int i=0;i<eventCount; i++) {
    Event event = new Event();
    event.setWhat("1");
    event.setWhen(date.getMillis());
    event.setData("2");
    event.setTags("event");
    eventMap = event.toMap();
    date = date.minusSeconds(stepInSeconds);
    searchIO.insert(tenant, eventMap);
  }
}

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

@Override
  public Object apply() {
    DateTime now = null == dateTime ? DateTime.now() : dateTime;
    if (null != deltaInSeconds) {
      int delta = deltaInSeconds;
      now = delta < 0 ? now.minusSeconds(-1 * delta) : now.plusSeconds(delta);
    }
    return now;
  }
}

代码示例来源:origin: com.github.fosin/cdp-utils

/**
 * 2014-03-02 23:00:23  ===   2014-03-02 23:59:59
 *
 * @param ts ts
 * @return 结果
 */
public static <T extends Date> T lastOfDay(T ts) {
  checkNotNull(ts);
  T cloned = (T) ts.clone();
  cloned.setTime(new DateTime(ts.getTime()).withTime(0, 0, 0, 0).plusDays(1).minusSeconds(1).getMillis());
  return cloned;
}

代码示例来源:origin: org.modeshape/modeshape-graph

/**
 * {@inheritDoc}
 * 
 * @see org.modeshape.graph.property.DateTime#minusSeconds(int)
 */
public org.modeshape.graph.property.DateTime minusSeconds( int seconds ) {
  return new JodaDateTime(this.instance.minusSeconds(seconds));
}

代码示例来源:origin: dmart28/gcplot

private void edge(GCEvent event) {
    edge = event.occurred();
    edgeMinus = edge.minusSeconds(windowSeconds);
  }
}

代码示例来源:origin: com.github.fosin/cdp-utils

/**
 * 2014-03-02 23:00:23  ===   2014-03-31 23:59:59
 *
 * @param ts ts
 * @return 结果
 */
public static <T extends Date> T lastOfMonth(T ts) {
  checkNotNull(ts);
  T cloned = (T) ts.clone();
  cloned.setTime(new DateTime(ts.getTime()).withTime(0, 0, 0, 0).withDayOfMonth(1).plusMonths(1).minusSeconds(1).getMillis());
  return cloned;
}

代码示例来源:origin: com.github.fosin/cdp-utils

/**
 * 2014-03-02 23:00:23  ===   2014-12-31 23:59:59
 *
 * @param ts ts
 * @return 结果
 */
public static <T extends Date> T lastOfYear(T ts) {
  checkNotNull(ts);
  T cloned = (T) ts.clone();
  cloned.setTime(new DateTime(ts.getTime()).withTime(0, 0, 0, 0).withDayOfYear(1).minusSeconds(1).plusYears(1).getMillis());
  return cloned;
}

代码示例来源:origin: rackerlabs/blueflood

@Test
public void testDecrementUnits() {
  testFormat("now-10s", nowDateTime().minusSeconds(10));
  testFormat("now-15min", nowDateTime().minusMinutes(15));
  testFormat("now-100h", nowDateTime().minusHours(100));
  testFormat("now-2d", nowDateTime().minusDays(2));
  testFormat("now-6mon", nowDateTime().minusMonths(6));
  testFormat("now-5y", nowDateTime().minusYears(5));
  testFormat("-6h", nowDateTime().minusHours(6));
}

代码示例来源:origin: io.codearte.jfairy/jfairy

public DateTime randomDateInThePast(int maxYearsEarlier) {
  checkArgument(maxYearsEarlier >= 0, "%s has to be >= 0", maxYearsEarlier);
  DateTime currentDate = timeProvider.getCurrentDate();
  DateTime latestDateInThePast = currentDate.minusSeconds(SECONDS_BEFORE_TO_BE_IN_THE_PAST);
  DateTime maxYearsEarlierDate = currentDate.minusYears(maxYearsEarlier);
  return randomDateBetweenTwoDates(maxYearsEarlierDate, latestDateInThePast);
}

代码示例来源:origin: org.pac4j/pac4j-saml

protected final boolean isDateValid(final DateTime issueInstant, final int interval) {
  final DateTime now = DateTime.now(DateTimeZone.UTC);
  final DateTime before = now.plusSeconds(acceptedSkew);
  final DateTime after = now.minusSeconds(acceptedSkew + interval);
  final DateTime issueInstanceUtc = issueInstant.toDateTime(DateTimeZone.UTC);
  final boolean isDateValid = issueInstanceUtc.isBefore(before) && issueInstanceUtc.isAfter(after);
  if (!isDateValid) {
    logger.warn("interval={},before={},after={},issueInstant={}", interval, before.toDateTime(issueInstanceUtc.getZone()),
      after.toDateTime(issueInstanceUtc.getZone()), issueInstanceUtc);
  }
  return isDateValid;
}

代码示例来源:origin: org.jasig.portal/uPortal-portlets

@ResourceMapping("intervalCount")
  public ModelAndView getIntervalCount(
      @RequestParam("interval") AggregationInterval interval,
      @RequestParam("start") DateMidnight start,
      @RequestParam("end") DateMidnight end)
      throws TypeMismatchException {
    final int intervalsBetween =
        this.intervalHelper.intervalsBetween(
            interval, start.toDateTime(), end.plusDays(1).toDateTime().minusSeconds(1));
    return new ModelAndView("json", "intervalsBetween", intervalsBetween);
  }
}

代码示例来源:origin: blurpy/kouchat-android

/**
   * Returns if the specified date is "now", plus/minus 5 seconds of slack.
   *
   * @param date The date to check.
   * @return If the date is "now".
   */
  public static boolean isNow(final Date date) {
    final Interval nowPlusMinus5Seconds = new Interval(new DateTime().minusSeconds(5),
                              new DateTime().plusSeconds(5));

    return nowPlusMinus5Seconds.contains(date.getTime());
  }
}

代码示例来源:origin: blurpy/kouchat-android

@Test
public void howLongFromNowShouldReturnCorrectWhenMinutes() {
  final DateTime then = new DateTime()
      .minusSeconds(12)
      .minusMinutes(5);
  final String howLongFromNow = dateTools.howLongFromNow(then.toDate().getTime());
  assertEquals("0 days, 00:05:12", howLongFromNow);
}

代码示例来源:origin: blurpy/kouchat-android

@Test
  public void howLongFromNowShouldReturnCorrectWhenDays() {
    final DateTime then = new DateTime()
        .minusSeconds(6)
        .minusMinutes(44)
        .minusHours(14)
        .minusDays(2);
    final String howLongFromNow = dateTools.howLongFromNow(then.toDate().getTime());

    // Note: this might fail when logonTime is summer time and current time is not
    assertEquals("2 days, 14:44:06", howLongFromNow);
  }
}

相关文章

DateTime类方法