org.joda.time.Seconds类的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(12.5k)|赞(0)|评价(0)|浏览(122)

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

Seconds介绍

[英]An immutable time period representing a number of seconds.

Seconds is an immutable period that can only store seconds. It does not store years, months or hours for example. As such it is a type-safe way of representing a number of seconds in an application.

The number of seconds is set in the constructor, and may be queried using getSeconds(). Basic mathematical operations are provided - plus(), minus(), multipliedBy() and dividedBy().

Seconds is thread-safe and immutable.
[中]表示秒数的不可变时间段。
Seconds是一个不可变的周期,只能存储秒数。例如,它不存储年、月或小时。因此,它是一种在应用程序中表示秒数的类型安全方式。
秒数在构造函数中设置,可以使用getSeconds()进行查询。提供了基本的数学运算-plus()minus()multipliedBy()dividedBy()
Seconds是线程安全且不可变的。

代码示例

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

private static boolean isLeaked(Map<QueryId, BasicQueryInfo> queryIdToInfo, QueryId queryId)
{
  BasicQueryInfo queryInfo = queryIdToInfo.get(queryId);
  if (queryInfo == null) {
    return true;
  }
  DateTime queryEndTime = queryInfo.getQueryStats().getEndTime();
  if (queryInfo.getState() == RUNNING || queryEndTime == null) {
    return false;
  }
  return secondsBetween(queryEndTime, now()).getSeconds() >= DEFAULT_LEAK_CLAIM_DELTA_SEC;
}

代码示例来源:origin: Graylog2/graylog2-server

@Override
@JsonIgnore
public DateTime getFrom() {
  // TODO this should be computed once
  if (range() > 0) {
    return Tools.nowUTC().minus(Seconds.seconds(range()));
  }
  return new DateTime(0, DateTimeZone.UTC);
}

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

/**
 * Returns a new instance with the specified number of seconds taken away.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param seconds  the amount of seconds to take away, may be negative
 * @return the new period minus the specified number of seconds
 * @throws ArithmeticException if the result overflows an int
 */
public Seconds minus(int seconds) {
  return plus(FieldUtils.safeNegate(seconds));
}

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

/**
 * Resolves singletons.
 * 
 * @return the singleton instance
 */
private Object readResolve() {
  return Seconds.seconds(getValue());
}

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

/**
 * Returns a new instance with the specified number of seconds added.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param seconds  the amount of seconds to add, may be negative, null means zero
 * @return the new period plus the specified number of seconds
 * @throws ArithmeticException if the result overflows an int
 */
public Seconds plus(Seconds seconds) {
  if (seconds == null) {
    return this;
  }
  return plus(seconds.getValue());
}

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

/**
 * Returns a new instance with the seconds multiplied by the specified scalar.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param scalar  the amount to multiply by, may be negative
 * @return the new period multiplied by the specified scalar
 * @throws ArithmeticException if the result overflows an int
 */
public Seconds multipliedBy(int scalar) {
  return Seconds.seconds(FieldUtils.safeMultiply(getValue(), scalar));
}

代码示例来源:origin: pl.edu.icm.synat/synat-business-services-impl

@RequiresServiceRole(roleName = "WRITE")
public void cleanCache() {
  final DateTime now = new DateTime();
  for (Iterator<Map.Entry<String, MetadataNearRealtimeCacheEntry>> itr = cache.entrySet().iterator(); itr.hasNext();) {
    Map.Entry<String, MetadataNearRealtimeCacheEntry> entry = itr.next();
    DateTime entryTime = new DateTime(entry.getValue().getTimestamp());
    final Seconds seconds = Seconds.secondsBetween(entryTime, now);
    if (seconds.getSeconds() > thresholdInSeconds) {
      itr.remove();
    }
  }
}

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

DateTime now = DateTime.now(time.getZone()).withMillisOfSecond(0);
DateTime timeDt = new DateTime(time).withMillisOfSecond(0);
boolean past = !now.isBefore(timeDt);
Interval interval = past ? new Interval(timeDt, now) : new Interval(now, timeDt);
if (Minutes.minutesIn(interval).isLessThan(Minutes.ONE)) {
  count = Seconds.secondsIn(interval).getSeconds();
  if (past) {
    if (abbrevRelative) {
else if (Hours.hoursIn(interval).isLessThan(Hours.ONE)) {
  count = Minutes.minutesIn(interval).getMinutes();
  if (past) {
    if (abbrevRelative) {
  count = Hours.hoursIn(interval).getHours();
  if (past) {
    if (abbrevRelative) {

代码示例来源:origin: uk.co.nichesolutions.presto/presto-main

@Test
public void testDateDiffTime()
{
  DateTime baseDateTime = new DateTime(1970, 1, 1, 7, 2, 9, 678, DATE_TIME_ZONE);
  String baseDateTimeLiteral = "TIME '07:02:09.678'";
  assertFunction("date_diff('millisecond', " + baseDateTimeLiteral + ", " + TIME_LITERAL + ")", BIGINT, millisBetween(baseDateTime, TIME));
  assertFunction("date_diff('second', " + baseDateTimeLiteral + ", " + TIME_LITERAL + ")", BIGINT, secondsBetween(baseDateTime, TIME).getSeconds());
  assertFunction("date_diff('minute', " + baseDateTimeLiteral + ", " + TIME_LITERAL + ")", BIGINT, minutesBetween(baseDateTime, TIME).getMinutes());
  assertFunction("date_diff('hour', " + baseDateTimeLiteral + ", " + TIME_LITERAL + ")", BIGINT, hoursBetween(baseDateTime, TIME).getHours());
  DateTime weirdBaseDateTime = new DateTime(1970, 1, 1, 7, 2, 9, 678, WEIRD_ZONE);
  String weirdBaseDateTimeLiteral = "TIME '07:02:09.678 +07:09'";
  assertFunction("date_diff('millisecond', " + weirdBaseDateTimeLiteral + ", " + WEIRD_TIME_LITERAL + ")", BIGINT, millisBetween(weirdBaseDateTime, WEIRD_TIME));
  assertFunction("date_diff('second', " + weirdBaseDateTimeLiteral + ", " + WEIRD_TIME_LITERAL + ")", BIGINT, secondsBetween(weirdBaseDateTime, WEIRD_TIME).getSeconds());
  assertFunction("date_diff('minute', " + weirdBaseDateTimeLiteral + ", " + WEIRD_TIME_LITERAL + ")", BIGINT, minutesBetween(weirdBaseDateTime, WEIRD_TIME).getMinutes());
  assertFunction("date_diff('hour', " + weirdBaseDateTimeLiteral + ", " + WEIRD_TIME_LITERAL + ")", BIGINT, hoursBetween(weirdBaseDateTime, WEIRD_TIME).getHours());
}

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

@Test
public void testDateDiffTimestamp()
  DateTime baseDateTime = new DateTime(1960, 5, 3, 7, 2, 9, 678, isLegacyTimestamp(session) ? DATE_TIME_ZONE : UTC_TIME_ZONE);
  String baseDateTimeLiteral = "TIMESTAMP '1960-05-03 07:02:09.678'";
  assertFunction("date_diff('second', " + baseDateTimeLiteral + ", " + TIMESTAMP_LITERAL + ")", BIGINT, (long) secondsBetween(baseDateTime, TIMESTAMP).getSeconds());
  assertFunction("date_diff('minute', " + baseDateTimeLiteral + ", " + TIMESTAMP_LITERAL + ")", BIGINT, (long) minutesBetween(baseDateTime, TIMESTAMP).getMinutes());
  assertFunction("date_diff('hour', " + baseDateTimeLiteral + ", " + TIMESTAMP_LITERAL + ")", BIGINT, (long) hoursBetween(baseDateTime, TIMESTAMP).getHours());
  assertFunction("date_diff('day', " + baseDateTimeLiteral + ", " + TIMESTAMP_LITERAL + ")", BIGINT, (long) daysBetween(baseDateTime, TIMESTAMP).getDays());
  assertFunction("date_diff('week', " + baseDateTimeLiteral + ", " + TIMESTAMP_LITERAL + ")", BIGINT, (long) weeksBetween(baseDateTime, TIMESTAMP).getWeeks());
  assertFunction("date_diff('year', " + baseDateTimeLiteral + ", " + TIMESTAMP_LITERAL + ")", BIGINT, (long) yearsBetween(baseDateTime, TIMESTAMP).getYears());
  DateTime weirdBaseDateTime = new DateTime(1960, 5, 3, 7, 2, 9, 678, WEIRD_DATE_TIME_ZONE);
  String weirdBaseDateTimeLiteral = "TIMESTAMP '1960-05-03 07:02:09.678 +07:09'";
  assertFunction("date_diff('second', " + weirdBaseDateTimeLiteral + ", " + WEIRD_TIMESTAMP_LITERAL + ")",
      BIGINT,
      (long) secondsBetween(weirdBaseDateTime, WEIRD_TIMESTAMP).getSeconds());
  assertFunction("date_diff('minute', " + weirdBaseDateTimeLiteral + ", " + WEIRD_TIMESTAMP_LITERAL + ")",
      BIGINT,
      (long) minutesBetween(weirdBaseDateTime, WEIRD_TIMESTAMP).getMinutes());
  assertFunction("date_diff('hour', " + weirdBaseDateTimeLiteral + ", " + WEIRD_TIMESTAMP_LITERAL + ")",
      BIGINT,
      (long) hoursBetween(weirdBaseDateTime, WEIRD_TIMESTAMP).getHours());
  assertFunction("date_diff('day', " + weirdBaseDateTimeLiteral + ", " + WEIRD_TIMESTAMP_LITERAL + ")",
      BIGINT,

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

public <T> Future<T> on(DateTime instant, Callable<T> callable) {
  if (LOGGER.isTraceEnabled()) {
    LOGGER.trace("schedule callable[%s] on %s", callable, instant);
  }
  DateTime now = DateTime.now();
  E.illegalArgumentIf(instant.isBefore(now));
  Seconds seconds = Seconds.secondsBetween(now, instant);
  return executor().schedule(callable, seconds.getSeconds(), TimeUnit.SECONDS);
}

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

private void delayedSchedule(JobManager manager, Job job) {
  DateTime now = DateTime.now();
  // add one seconds to prevent the next time be the current time (now)
  DateTime next = cronExpr.nextTimeAfter(now.plusSeconds(1));
  Seconds seconds = Seconds.secondsBetween(now, next);
  ScheduledFuture future = manager.executor().schedule(job, seconds.getSeconds(), TimeUnit.SECONDS);
  manager.futureScheduled(job.id(), future);
}

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

/**
 * Converts this period to a period in seconds assuming a
 * 7 day week, 24 hour day, 60 minute hour and 60 second minute.
 * <p>
 * This method allows you to convert between different types of period.
 * However to achieve this it makes the assumption that all
 * weeks are 7 days, all days are 24 hours, all hours are 60 minutes and
 * all minutes are 60 seconds. This is not true when daylight savings time
 * is considered, and may also not be true for some unusual chronologies.
 * However, it is included as it is a useful operation for many
 * applications and business rules.
 * <p>
 * If the period contains years or months, an exception will be thrown.
 * 
 * @return a period representing the number of standard seconds in this period
 * @throws UnsupportedOperationException if the period contains years or months
 * @throws ArithmeticException if the number of seconds is too large to be represented
 * @since 1.5
 */
public Seconds toStandardSeconds() {
  checkYearsAndMonths("Seconds");
  long seconds = getMillis() / DateTimeConstants.MILLIS_PER_SECOND;
  seconds = FieldUtils.safeAdd(seconds, getSeconds());
  seconds = FieldUtils.safeAdd(seconds, ((long) getMinutes()) * ((long) DateTimeConstants.SECONDS_PER_MINUTE));
  seconds = FieldUtils.safeAdd(seconds, ((long) getHours()) * ((long) DateTimeConstants.SECONDS_PER_HOUR));
  seconds = FieldUtils.safeAdd(seconds, ((long) getDays()) * ((long) DateTimeConstants.SECONDS_PER_DAY));
  seconds = FieldUtils.safeAdd(seconds, ((long) getWeeks()) * ((long) DateTimeConstants.SECONDS_PER_WEEK));
  return Seconds.seconds(FieldUtils.safeToInt(seconds));
}

代码示例来源:origin: Graylog2/graylog2-server

@Override
public boolean shouldRepeatNotifications(AlertCondition alertCondition, Alert alert) {
  // Do not repeat notifications if alert has no state, is resolved or the option to repeat notifications is disabled
  if (!alert.isInterval() || isResolved(alert) || !alertCondition.shouldRepeatNotifications()) {
    return false;
  }
  // Repeat notifications if no grace period is set, avoiding looking through the notification history
  if (alertCondition.getGrace() == 0) {
    return true;
  }
  AlarmCallbackHistory lastTriggeredAlertHistory = null;
  for (AlarmCallbackHistory history : alarmCallbackHistoryService.getForAlertId(alert.getId())) {
    if (lastTriggeredAlertHistory == null || lastTriggeredAlertHistory.createdAt().isBefore(history.createdAt())) {
      lastTriggeredAlertHistory = history;
    }
  }
  // Repeat notifications if no alert was ever triggered for this condition
  if (lastTriggeredAlertHistory == null) {
    return true;
  }
  final int lastAlertSecondsAgo = Seconds.secondsBetween(lastTriggeredAlertHistory.createdAt(), Tools.nowUTC()).getSeconds();
  return lastAlertSecondsAgo >= alertCondition.getGrace() * 60;
}

代码示例来源:origin: com.linkedin.datafu/datafu

public Sessionize(String timeSpec)
{
 Period p = new Period("PT" + timeSpec.toUpperCase());
 this.millis = p.toStandardSeconds().getSeconds() * 1000;
 cleanup();
}

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

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

代码示例来源:origin: apache/eagle

@Test
public void testJodaTimePeriod() throws ParseException {
  String periodText = "PT10m";
  Period period = new Period(periodText);
  int seconds = period.toStandardSeconds().getSeconds();
  Assert.assertEquals(600, seconds);
  Assert.assertEquals(60, period.toStandardSeconds().dividedBy(10).getSeconds());
}

代码示例来源:origin: com.fasterxml.jackson.datatype/jackson-datatype-joda

return new Period(p.getLongValue());    
rp = Seconds.seconds( periodValue );
rp = Minutes.minutes( periodValue );
rp = Hours.hours( periodValue );

代码示例来源:origin: co.cask.wrangler/wrangler-core

/**
 * Converts seconds to mins.
 *
 * @param seconds to be converted.
 * @return mins equivalent of seconds
 */
public static int SECONDS_TO_MINUTES(int seconds) {
 Period period = new Period(Seconds.seconds(seconds));
 return period.toStandardMinutes().getMinutes();
}

代码示例来源:origin: co.cask.wrangler/wrangler-core

/**
 * Converts seconds to hours.
 *
 * @param seconds to be converted.
 * @return hours equivalent of seconds
 */
public static int SECONDS_TO_HOURS(int seconds) {
 Period period = new Period(Seconds.seconds(seconds));
 return period.toStandardHours().getHours();
}

相关文章