java.time.ZonedDateTime.minusMinutes()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(9.6k)|赞(0)|评价(0)|浏览(156)

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

ZonedDateTime.minusMinutes介绍

[英]Returns a copy of this ZonedDateTime with the specified period in minutes subtracted.

This operates on the instant time-line, such that subtracting one minute will always be a duration of one minute earlier. This may cause the local date-time to change by an amount other than one minute. Note that this is a different approach to that used by days, months and years.

This instance is immutable and unaffected by this method call.
[中]返回此ZoneDateTime的副本,并减去指定的时间段(以分钟为单位)。
这是在即时时间线上进行的,因此减去一分钟的持续时间将始终提前一分钟。这可能会导致本地日期时间的变化量超过一分钟。请注意,这与日、月和年使用的方法不同。
此实例是不可变的,不受此方法调用的影响。

代码示例

代码示例来源:origin: org.elasticsearch/elasticsearch

public ZonedDateTime minusMinutes(long amount) {
  return dt.minusMinutes(amount);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

public ZonedDateTime minusMinutes(long amount) {
  return dt.minusMinutes(amount);
}

代码示例来源:origin: apache/servicemix-bundles

public ZonedDateTime minusMinutes(long amount) {
  return dt.minusMinutes(amount);
}

代码示例来源:origin: org.mycore/mycore-restapi

public static Optional<String> getToken(MCRUserInformation userInformation, String remoteIp) {
  ZonedDateTime currentTime = ZonedDateTime.now(ZoneOffset.UTC);
  return Optional.ofNullable(userInformation)
    .map(MCRJWTUtil::getJWTBuilder)
    .map(b -> {
      return b.withAudience(AUDIENCE)
        .withClaim(MCRJWTUtil.JWT_CLAIM_IP, remoteIp)
        .withExpiresAt(Date.from(currentTime.plusMinutes(EXPIRATION_TIME_MINUTES).toInstant()))
        .withNotBefore(Date.from(currentTime.minusMinutes(EXPIRATION_TIME_MINUTES).toInstant()))
        .sign(MCRJWTUtil.getJWTAlgorithm());
    });
}

代码示例来源:origin: com.infotel.seleniumRobot/core

try {
  if (Files.readAttributes(directory.toPath(), BasicFileAttributes.class).lastAccessTime().toInstant().atZone(ZoneOffset.UTC).toLocalTime()
      .isBefore(ZonedDateTime.now().minusMinutes(300).withZoneSameInstant(ZoneOffset.UTC).toLocalTime())) {
    FileUtils.deleteDirectory(directory);

代码示例来源:origin: com.infotel.seleniumRobot/grid-extensions

try {
  if (Files.readAttributes(directory.toPath(), BasicFileAttributes.class).lastAccessTime().toInstant().atZone(ZoneOffset.UTC).toLocalTime()
      .isBefore(ZonedDateTime.now().minusMinutes(300).withZoneSameInstant(ZoneOffset.UTC).toLocalTime())) {
    FileUtils.deleteDirectory(directory);

代码示例来源:origin: yahoo/sherlock

/**
 * Decrement a zoned date time by a certain
 * amount of this granularity.
 *
 * @param date   zoned date time to decrease
 * @param amount the number of times to decrease
 * @return copy of the zoned date time
 */
public ZonedDateTime decrement(ZonedDateTime date, int amount) {
  switch (this) {
    case MINUTE:
      return date.minusMinutes(amount);
    case HOUR:
      return date.minusHours(amount);
    case DAY:
      return date.minusDays(amount);
    case WEEK:
      return date.minusWeeks(amount);
    case MONTH:
      return date.minusMonths(amount);
    default:
      return date.minusHours(amount);
  }
}

代码示例来源:origin: yahoo/sherlock

/**
 * Subtract granularity intervals of this type
 * from a given date time.
 *
 * @param now       the time to subtract intervals from
 * @param intervals the number of intervals to subtract
 * @param granularityRange range of granularity to aggregate on
 * @return a copied ZonedDateTime with the intervals subtracted
 */
public ZonedDateTime subtractIntervals(ZonedDateTime now, int intervals, int granularityRange) {
  int n = intervals - (intervals % granularityRange);
  switch (this) {
    case MINUTE:
      return now.minusMinutes(n);
    case HOUR:
      return now.minusHours(n);
    case DAY:
      return now.minusDays(n);
    case WEEK:
      return now.minusWeeks(n);
    case MONTH:
      return now.minusMonths(n);
    default:
      return now.minusHours(n);
  }
}

代码示例来源:origin: commercetools/commercetools-jvm-sdk

@Test
public void queryByDateTime() {
  checkQuery(fields -> fields.ofDateTime(DATETIME_FIELD_NAME).isGreaterThan(ZONED_DATE_TIME.minusMinutes(1)));
}

代码示例来源:origin: com.goldmansachs.jdmn/jdmn-core

@Override
  public ZonedDateTime timeSubtractDuration(ZonedDateTime time, Duration duration) {
    if (time == null || duration == null) {
      return null;
    }

    try {
      int hours = duration.getHours();
      int minutes = duration.getMinutes();
      int seconds = duration.getSeconds();
      if (duration.getSign() == -1) {
        return time
            .plusHours(hours)
            .plusMinutes(minutes)
            .plusSeconds(seconds);
      } else {
        return time
            .minusHours(hours)
            .minusMinutes(minutes)
            .minusSeconds(seconds);
      }
    } catch (Throwable e) {
      String message = String.format("timeSubtract(%s, %s)", time, duration);
      logError(message, e);
      return null;
    }
  }
}

代码示例来源:origin: com.goldmansachs.jdmn/jdmn-core

@Override
public ZonedDateTime timeAddDuration(ZonedDateTime time, Duration duration) {
  if (time == null || duration == null) {
    return null;
  }
  try {
    int hours = duration.getHours();
    int minutes = duration.getMinutes();
    int seconds = duration.getSeconds();
    if (duration.getSign() == -1) {
      return time
          .minusHours(hours)
          .minusMinutes(minutes)
          .minusSeconds(seconds);
    } else {
      return time
          .plusHours(hours)
          .plusMinutes(minutes)
          .plusSeconds(seconds);
    }
  } catch (Throwable e) {
    String message = String.format("timeAdd(%s, %s)", time, duration);
    logError(message, e);
    return null;
  }
}

代码示例来源:origin: goldmansachs/jdmn

@Override
public ZonedDateTime timeAddDuration(ZonedDateTime time, Duration duration) {
  if (time == null || duration == null) {
    return null;
  }
  try {
    int hours = duration.getHours();
    int minutes = duration.getMinutes();
    int seconds = duration.getSeconds();
    if (duration.getSign() == -1) {
      return time
          .minusHours(hours)
          .minusMinutes(minutes)
          .minusSeconds(seconds);
    } else {
      return time
          .plusHours(hours)
          .plusMinutes(minutes)
          .plusSeconds(seconds);
    }
  } catch (Throwable e) {
    String message = String.format("timeAdd(%s, %s)", time, duration);
    logError(message, e);
    return null;
  }
}

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

@Test
public void testMinutes() throws DatatypeConfigurationException, ValueExprEvaluationException {
  DatatypeFactory dtf = DatatypeFactory.newInstance();
  ZonedDateTime zTime = testThisTimeDate;
  String time = zTime.format(DateTimeFormatter.ISO_INSTANT);
  ZonedDateTime zTime1 = zTime.minusMinutes(1);
  String time1 = zTime1.format(DateTimeFormatter.ISO_INSTANT);
  Literal now = VF.createLiteral(dtf.newXMLGregorianCalendar(time));
  Literal nowMinusOne = VF.createLiteral(dtf.newXMLGregorianCalendar(time1));
  DateTimeWithinPeriod func = new DateTimeWithinPeriod();
  assertEquals(TRUE, func.evaluate(VF, now, now,VF.createLiteral(1),OWLTime.MINUTES_URI));
  assertEquals(FALSE, func.evaluate(VF, now, nowMinusOne,VF.createLiteral(1),OWLTime.MINUTES_URI));
  assertEquals(TRUE, func.evaluate(VF, now, nowMinusOne,VF.createLiteral(2),OWLTime.MINUTES_URI));
}

代码示例来源:origin: goldmansachs/jdmn

@Override
  public ZonedDateTime timeSubtractDuration(ZonedDateTime time, Duration duration) {
    if (time == null || duration == null) {
      return null;
    }

    try {
      int hours = duration.getHours();
      int minutes = duration.getMinutes();
      int seconds = duration.getSeconds();
      if (duration.getSign() == -1) {
        return time
            .plusHours(hours)
            .plusMinutes(minutes)
            .plusSeconds(seconds);
      } else {
        return time
            .minusHours(hours)
            .minusMinutes(minutes)
            .minusSeconds(seconds);
      }
    } catch (Throwable e) {
      String message = String.format("timeSubtract(%s, %s)", time, duration);
      logError(message, e);
      return null;
    }
  }
}

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

ZonedDateTime time = ZonedDateTime.now();
ZonedDateTime zTime1 = time.minusMinutes(30);
String time1 = zTime1.format(DateTimeFormatter.ISO_INSTANT);
ZonedDateTime zTime2 = zTime1.minusMinutes(30);
String time2 = zTime2.format(DateTimeFormatter.ISO_INSTANT);
ZonedDateTime zTime3 = zTime2.minusMinutes(30);
String time3 = zTime3.format(DateTimeFormatter.ISO_INSTANT);
ZonedDateTime zTime4 = zTime3.minusMinutes(30);
String time4 = zTime4.format(DateTimeFormatter.ISO_INSTANT);

代码示例来源:origin: UniversaBlockchain/universa

@Test
public void checkRegisterContractExpiresAtReсentPastTime() throws Exception{
  Contract oldContract = Contract.fromDslFile(ROOT_PATH + "simple_root_contract.yml");
  oldContract.addSignerKeyFromFile(ROOT_PATH+"_xer0yfe2nn1xthc.private.unikey");
  oldContract.getDefinition().setExpiresAt(oldContract.getCreatedAt().minusMinutes(1));
  oldContract.seal();
  oldContract.check();
  oldContract.traceErrors();
  System.out.println("Contract is valid: " + oldContract.isOk());
  assertFalse(oldContract.isOk());
}

代码示例来源:origin: UniversaBlockchain/universa

@Test
public void checkContractExpiresAtResentPastTime() throws Exception{
  Contract oldContract = Contract.fromDslFile(rootPath + "simple_root_contract.yml");
  oldContract.addSignerKeyFromFile(rootPath+"_xer0yfe2nn1xthc.private.unikey");
  oldContract.getDefinition().setExpiresAt(oldContract.getCreatedAt().minusMinutes(1));
  oldContract.seal();
  oldContract.check();
  oldContract.traceErrors();
  System.out.println("Contract is valid: " + oldContract.isOk());
  assertFalse(oldContract.isOk());
}

代码示例来源:origin: com.goldmansachs.jdmn/jdmn-core

.minusDays(days)
      .minusHours(hours)
      .minusMinutes(minutes)
      .minusSeconds(seconds);
} else {

代码示例来源:origin: UniversaBlockchain/universa

@Ignore
@Test
public void checkRevisionExpiresAtReсentPastTime() throws Exception{
  Contract baseContract = Contract.fromDslFile(ROOT_PATH + "DeLoreanOwnership.yml");
  PrivateKey manufacturePrivateKey = new PrivateKey(Do.read(ROOT_PATH + "_xer0yfe2nn1xthc.private.unikey"));
  PrivateKey ownerPrivateKey = new PrivateKey(Do.read(ROOT_PATH + "keys/marty_mcfly.private.unikey"));
  baseContract.addSignerKey(manufacturePrivateKey);
  baseContract.seal();
  baseContract.check();
  baseContract.traceErrors();
  System.out.println("Base contract is valid: " + baseContract.isOk());
  registerAndCheckApproved(baseContract);
  Contract revContract  = baseContract.createRevision(ownerPrivateKey);
  revContract.setExpiresAt(revContract.getCreatedAt().minusMinutes(1));
  revContract.seal();
  revContract.check();
  revContract.traceErrors();
  assertTrue(revContract.isOk());
}

代码示例来源:origin: UniversaBlockchain/universa

b = revTemp.serialize(new BiSerializer());
seconds = ZonedDateTime.now().minusDays(4).minusMinutes(1).toEpochSecond();
b.getBinder("state").getBinder("created_at").set("seconds", seconds);

相关文章

ZonedDateTime类方法