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

x33g5p2x  于2022-01-23 转载在 其他  
字(12.8k)|赞(0)|评价(0)|浏览(319)

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

LocalDateTime.minusMinutes介绍

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

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

代码示例

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

@Test
public void testDate()
{
  // Note: there is identical test for PostgreSQL
  ZoneId jvmZone = ZoneId.systemDefault();
  checkState(jvmZone.getId().equals("America/Bahia_Banderas"), "This test assumes certain JVM time zone");
  LocalDate dateOfLocalTimeChangeForwardAtMidnightInJvmZone = LocalDate.of(1970, 1, 1);
  verify(jvmZone.getRules().getValidOffsets(dateOfLocalTimeChangeForwardAtMidnightInJvmZone.atStartOfDay()).isEmpty());
  ZoneId someZone = ZoneId.of("Europe/Vilnius");
  LocalDate dateOfLocalTimeChangeForwardAtMidnightInSomeZone = LocalDate.of(1983, 4, 1);
  verify(someZone.getRules().getValidOffsets(dateOfLocalTimeChangeForwardAtMidnightInSomeZone.atStartOfDay()).isEmpty());
  LocalDate dateOfLocalTimeChangeBackwardAtMidnightInSomeZone = LocalDate.of(1983, 10, 1);
  verify(someZone.getRules().getValidOffsets(dateOfLocalTimeChangeBackwardAtMidnightInSomeZone.atStartOfDay().minusMinutes(1)).size() == 2);
  DataTypeTest testCases = DataTypeTest.create()
      .addRoundTrip(dateDataType(), LocalDate.of(1952, 4, 3)) // before epoch
      .addRoundTrip(dateDataType(), LocalDate.of(1970, 1, 1))
      .addRoundTrip(dateDataType(), LocalDate.of(1970, 2, 3))
      .addRoundTrip(dateDataType(), LocalDate.of(2017, 7, 1)) // summer on northern hemisphere (possible DST)
      .addRoundTrip(dateDataType(), LocalDate.of(2017, 1, 1)) // winter on northern hemisphere (possible DST on southern hemisphere)
      .addRoundTrip(dateDataType(), dateOfLocalTimeChangeForwardAtMidnightInJvmZone)
      .addRoundTrip(dateDataType(), dateOfLocalTimeChangeForwardAtMidnightInSomeZone)
      .addRoundTrip(dateDataType(), dateOfLocalTimeChangeBackwardAtMidnightInSomeZone);
  for (String timeZoneId : ImmutableList.of(UTC_KEY.getId(), jvmZone.getId(), someZone.getId())) {
    Session session = Session.builder(getQueryRunner().getDefaultSession())
        .setTimeZoneKey(TimeZoneKey.getTimeZoneKey(timeZoneId))
        .build();
    testCases.execute(getQueryRunner(), session, mysqlCreateAndInsert("tpch.test_date"));
    testCases.execute(getQueryRunner(), session, prestoCreateAsSelect("test_date"));
  }
}

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

@Test
public void testDate()
{
  // Note: there is identical test for MySQL
  ZoneId jvmZone = ZoneId.systemDefault();
  checkState(jvmZone.getId().equals("America/Bahia_Banderas"), "This test assumes certain JVM time zone");
  LocalDate dateOfLocalTimeChangeForwardAtMidnightInJvmZone = LocalDate.of(1970, 1, 1);
  verify(jvmZone.getRules().getValidOffsets(dateOfLocalTimeChangeForwardAtMidnightInJvmZone.atStartOfDay()).isEmpty());
  ZoneId someZone = ZoneId.of("Europe/Vilnius");
  LocalDate dateOfLocalTimeChangeForwardAtMidnightInSomeZone = LocalDate.of(1983, 4, 1);
  verify(someZone.getRules().getValidOffsets(dateOfLocalTimeChangeForwardAtMidnightInSomeZone.atStartOfDay()).isEmpty());
  LocalDate dateOfLocalTimeChangeBackwardAtMidnightInSomeZone = LocalDate.of(1983, 10, 1);
  verify(someZone.getRules().getValidOffsets(dateOfLocalTimeChangeBackwardAtMidnightInSomeZone.atStartOfDay().minusMinutes(1)).size() == 2);
  DataTypeTest testCases = DataTypeTest.create()
      .addRoundTrip(dateDataType(), LocalDate.of(1952, 4, 3)) // before epoch
      .addRoundTrip(dateDataType(), LocalDate.of(1970, 1, 1))
      .addRoundTrip(dateDataType(), LocalDate.of(1970, 2, 3))
      .addRoundTrip(dateDataType(), LocalDate.of(2017, 7, 1)) // summer on northern hemisphere (possible DST)
      .addRoundTrip(dateDataType(), LocalDate.of(2017, 1, 1)) // winter on northern hemisphere (possible DST on southern hemisphere)
      .addRoundTrip(dateDataType(), dateOfLocalTimeChangeForwardAtMidnightInJvmZone)
      .addRoundTrip(dateDataType(), dateOfLocalTimeChangeForwardAtMidnightInSomeZone)
      .addRoundTrip(dateDataType(), dateOfLocalTimeChangeBackwardAtMidnightInSomeZone);
  for (String timeZoneId : ImmutableList.of(UTC_KEY.getId(), jvmZone.getId(), someZone.getId())) {
    Session session = Session.builder(getQueryRunner().getDefaultSession())
        .setTimeZoneKey(TimeZoneKey.getTimeZoneKey(timeZoneId))
        .build();
    testCases.execute(getQueryRunner(), session, postgresCreateAndInsert("tpch.test_date"));
    testCases.execute(getQueryRunner(), session, prestoCreateAsSelect("test_date"));
  }
}

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

public void subtract_minutes_from_date_in_java8 () 
{  
  LocalDateTime newYearsDay = LocalDateTime.of(2015, Month.JANUARY, 1, 0, 0);

LocalDateTime newYearsEve = newYearsDay.minusMinutes(1);// In your case use 5 here 

  java.time.format.DateTimeFormatter formatter =java.time.format.DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm:ss S");  

  logger.info(newYearsDay.format(formatter));

  logger.info(newYearsEve.format(formatter));
}

代码示例来源:origin: ioFog/Agent

public static boolean isStuck(String containerId) {
    List<LocalDateTime> datesOfRestart = restarts.computeIfAbsent(containerId, k -> new ArrayList<>());
    LocalDateTime now = LocalDateTime.now();

    datesOfRestart.removeIf(dateOfRestart -> dateOfRestart.isBefore(now.minusMinutes(INTERVAL_IN_MINUTES)));
    datesOfRestart.add(now);

    return datesOfRestart.size() >= ABNORMAL_NUMBER_OF_RESTARTS;
  }
}

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

LocalDateTime dt1 = LocalDateTime.ofInstant(Instant.ofEpochMilli(1429174464829L), ZoneId.systemDefault());
LocalDateTime dt2 = LocalDateTime.now().plusDays(1);

System.out.println(dt1);
System.out.println(dt2);

StringJoiner sj = new StringJoiner(":");
long hours = ChronoUnit.HOURS.between(dt1, dt2);
sj.add(Long.toString(hours));
dt2 = dt2.minusHours(hours);
long mins = ChronoUnit.MINUTES.between(dt1, dt2);
sj.add(Long.toString(mins));
dt2 = dt2.minusMinutes(mins);
long secs = ChronoUnit.SECONDS.between(dt1, dt2);
sj.add(Long.toString(secs));

System.out.println(sj);

代码示例来源:origin: cloudfoundry-incubator/multiapps-controller

private boolean isCacheValid(File filePath) {
  LocalDateTime lastChecked = updateTimesMap.get(filePath);
  LocalDateTime invalidateDeadline = LocalDateTime.now()
    .minusMinutes(updateTimeoutMinutes);
  return invalidateDeadline.isBefore(lastChecked);
}

代码示例来源:origin: IQSS/dataverse

public boolean doWeQueryAgainAllTime(Metric queriedMetric) {
  if (null == queriedMetric) { //never queried before
    return true;
  }
  int minutesUntilNextQuery = systemConfig.getMetricsCacheTimeoutMinutes();
  Date lastCalled = queriedMetric.getLastCalledDate();
  LocalDateTime ldt = LocalDateTime.ofInstant((new Date()).toInstant(), ZoneId.systemDefault());
  LocalDateTime ldtMinus = ldt.minusMinutes(minutesUntilNextQuery);
  Date todayMinus = Date.from(ldtMinus.atZone(ZoneId.systemDefault()).toInstant());
  //allow if today minus query wait is after last called time
  return (todayMinus.after(lastCalled));
}

代码示例来源:origin: com.scireum/sirius-db

/**
 * Creates a date range filtering on the last 15 minutes.
 *
 * @return a date range for the given interval
 */
public static DateRange lastFiveteenMinutes() {
  return new DateRange("15m",
             NLS.get("DateRange.15m"),
             LocalDateTime.now().minusMinutes(15),
             LocalDateTime.now());
}

代码示例来源:origin: com.scireum/sirius-db

/**
 * Creates a date range filtering on the last five minutes.
 *
 * @return a date range for the given interval
 */
public static DateRange lastFiveMinutes() {
  return new DateRange("5m", NLS.get("DateRange.5m"), LocalDateTime.now().minusMinutes(5), LocalDateTime.now());
}

代码示例来源:origin: com.microsoft.bot.connector/bot-connector

public static boolean isTrustedServiceUrl(URL url) {
  return !_trustHostNames.getOrDefault(url.getHost(), LocalDateTime.MIN).isBefore(LocalDateTime.now().minusMinutes(5));
}

代码示例来源:origin: com.scireum/sirius-search

/**
 * Creates a date range filtering on the last five minutes.
 *
 * @return a date range to be used in {@link Query#addDateRangeFacet(String, String, DateRange...)}
 */
public static DateRange lastFiveMinutes() {
  return new DateRange("5m", NLS.get("DateRange.5m"), LocalDateTime.now().minusMinutes(5), LocalDateTime.now());
}

代码示例来源:origin: com.scireum/sirius-search

/**
 * Creates a date range filtering on the last 15 minutes.
 *
 * @return a date range to be used in {@link Query#addDateRangeFacet(String, String, DateRange...)}
 */
public static DateRange lastFiveteenMinutes() {
  return new DateRange("15m",
             NLS.get("DateRange.15m"),
             LocalDateTime.now().minusMinutes(15),
             LocalDateTime.now());
}

代码示例来源:origin: Microsoft/botbuilder-java

public static boolean isTrustedServiceUrl(URL url) {
  return !trustHostNames.getOrDefault(url.getHost(), LocalDateTime.MIN).isBefore(LocalDateTime.now().minusMinutes(5));
}

代码示例来源:origin: IQSS/dataverse

public boolean doWeQueryAgainMonthly(Metric queriedMetric) {
  if (null == queriedMetric) { //never queried before
    return true;
  }
  String yyyymm = queriedMetric.getMetricDateString();
  String thisMonthYYYYMM = MetricsUtil.getCurrentMonth();
  Date lastCalled = queriedMetric.getLastCalledDate();
  LocalDateTime ldt = LocalDateTime.ofInstant((new Date()).toInstant(), ZoneId.systemDefault());
  int minutesUntilNextQuery = systemConfig.getMetricsCacheTimeoutMinutes();
  if (yyyymm.equals(thisMonthYYYYMM)) { //if this month
    LocalDateTime ldtMinus = ldt.minusMinutes(minutesUntilNextQuery);
    Date todayMinus = Date.from(ldtMinus.atZone(ZoneId.systemDefault()).toInstant());
    //allow if today minus query wait is after last called time
    return (todayMinus.after(lastCalled));
  } else {
    String lastRunYYYYMM = yyyymmFormat.format(lastCalled);
    //if queried was last run during the month it was querying.  
    //Allows one requery of a past month to make it up to date.
    return (lastRunYYYYMM.equals(yyyymm));
  }
}

代码示例来源:origin: Microsoft/botbuilder-java

public static boolean isTrustedServiceUrl(HttpUrl url) {
  return !trustHostNames.getOrDefault(url.host(), LocalDateTime.MIN).isBefore(LocalDateTime.now().minusMinutes(5));
}

代码示例来源:origin: chocotan/lolibox

@Scheduled(fixedRate = 120000)
  public void getResult() {
    LocalDateTime time = LocalDateTime.now();
    Date end = Date.from(time.atZone(ZoneId.systemDefault()).toInstant());
    time.minusDays(1);
    time.minusMinutes(60);
    Date start = Date.from(time.atZone(ZoneId.systemDefault()).toInstant());
    imgFileRepository.findByGreenStatus(1, start, end).forEach(img -> {
      try {
        float checkResult = greenService.getCheckResult(img.getGreenTaskId());
        boolean porn = checkResult > 90;
        imgFileRepository.updateGreenStatusById(porn ? 3 : 5, img.getId());
        imgFileRepository.updateGreenPointById(checkResult, img.getId());
      } catch (Throwable throwable) {
        imgFileRepository.updateGreenStatusById(4, img.getId());
      }
    });
  }
};

代码示例来源:origin: com.helger/ph-as4-servlet

@Override
protected void onExecute (@Nonnull final JobDataMap aJobDataMap,
             @Nonnull final IJobExecutionContext aContext) throws JobExecutionException
{
 final long nMins = aJobDataMap.getAsLong (KEY_MINUTES);
 final LocalDateTime aOldDT = PDTFactory.getCurrentLocalDateTime ().minusMinutes (nMins);
 final ICommonsList <String> aEvicted = MetaAS4Manager.getIncomingDuplicateMgr ().evictAllItemsBefore (aOldDT);
 if (aEvicted.isNotEmpty ())
  LOGGER.info ("Evicted " + aEvicted.size () + " incoming duplicate message IDs");
}

代码示例来源:origin: com.scireum/sirius-kernel

private static String formatSpokenRecentDateWithTime(LocalDateTime givenDateTime) {
  if (givenDateTime.isAfter(LocalDateTime.now().minusMinutes(30))) {
    return NLS.get("NLS.someMinutesAgo");
  }
  if (givenDateTime.isAfter(LocalDateTime.now().minusMinutes(59))) {
    return NLS.fmtr("NLS.nMinutesAgo")
         .set("minutes", Duration.between(givenDateTime, LocalDateTime.now()).toMinutes())
         .format();
  }
  if (givenDateTime.isAfter(LocalDateTime.now().minusHours(2))) {
    return NLS.get("NLS.oneHourAgo");
  }
  return NLS.fmtr("NLS.nHoursAgo")
       .set("hours", Duration.between(givenDateTime, LocalDateTime.now()).toHours())
       .format();
}

代码示例来源:origin: com.github.wslotkin/itinerator-generator

private boolean wouldExceedNextFixedEvent(Activity activityToAdd, Queue<Event> fixedEventQueue, Event lastEvent) {
  if (!fixedEventQueue.isEmpty()) {
    Event eventToAdd = activityToEvent(lastEvent, activityToAdd);
    Event nextFixedEvent = fixedEventQueue.peek();
    double travelTime = travelTime(activityToAdd, nextFixedEvent.getActivity());
    return wouldExceedTime(eventToAdd, nextFixedEvent.getEventTime().getStart().minusMinutes((int) travelTime));
  } else {
    return false;
  }
}

代码示例来源:origin: com.github.wslotkin/itinerator-generator

private Activity createPlaceholderActivity(Event fixedEvent, Event lastEvent) {
  final Location location;
  final long duration;
  if (lastEvent != null) {
    location = lastEvent.getActivity().getLocation();
    LocalDateTime endOfLastEvent = lastEvent.getEventTime().getEnd();
    double travelTimeFromLastEvent = travelTime(lastEvent.getActivity(), fixedEvent.getActivity());
    LocalDateTime timeToStartFixedEvent = fixedEvent.getEventTime().getStart().minusMinutes((int) travelTimeFromLastEvent);
    duration = between(endOfLastEvent, timeToStartFixedEvent).toMinutes();
  } else {
    location = fixedEvent.getActivity().getLocation();
    LocalDateTime timeToStartFixedEvent = fixedEvent.getEventTime().getStart();
    duration = between(startTime, timeToStartFixedEvent).toMinutes();
  }
  return createActivity("placeholder event", duration, location, ActivityType.PLACEHOLDER);
}

相关文章

LocalDateTime类方法