java.time.Duration.minusDays()方法的使用及代码示例

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

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

Duration.minusDays介绍

[英]Returns a copy of this duration with the specified duration in 24 hour days subtracted.

This instance is immutable and unaffected by this method call.
[中]返回此持续时间的副本,并减去指定的持续时间(24小时-天)。
此实例是不可变的,不受此方法调用的影响。

代码示例

代码示例来源:origin: stanfordnlp/CoreNLP

public static String elapsedTime(Date d1, Date d2){
 try{
  Duration period = Duration.between(d1.toInstant(), d2.toInstant());
  // Note: this will become easier with Java 9, using toDaysPart() etc.
  long days = period.toDays();
  period = period.minusDays(days);
  long hours = period.toHours();
  period = period.minusHours(hours);
  long minutes = period.toMinutes();
  period = period.minusMinutes(minutes);
  long seconds = period.getSeconds();
  return days + " days, " + hours + " hours, " + minutes + " minutes, " + seconds + " seconds";
 } catch(java.lang.IllegalArgumentException e) {
  log.warn(e);
 }
 return "";
}

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

@Override
  public Argument build(Duration duration, ConfigRegistry config) {
    Duration d = duration;
    final boolean isNegative = d.isNegative();
    if (isNegative) {
      d = d.negated();
    }
    final long days = d.toDays();
    if (days > Integer.MAX_VALUE) {
      throw new IllegalArgumentException(
          String.format("duration %s too large to be represented unambiguously as postgres interval",
              d));
    }
    d = d.minusDays(days);
    final int hours = (int) d.toHours();
    d = d.minusHours(hours);
    final int minutes = (int) d.toMinutes();
    d = d.minusMinutes(minutes);
    if (d.getNano() % 1000 != 0) {
      throw new IllegalArgumentException(
          String.format("duration %s too precise to represented as postgres interval", d));
    }
    double seconds = d.getSeconds() + d.getNano() / 1e9;
    final PGInterval interval = new PGInterval(0, 0, (int) days, hours, minutes, seconds);
    if (isNegative) {
      interval.scale(-1);
    }
    return ObjectArgument.of(interval, Types.OTHER);
  }
}

代码示例来源:origin: HotelsDotCom/styx

private static String formatTime(long timeInMilliseconds) {
  Duration duration = Duration.ofMillis(timeInMilliseconds);
  long days = duration.toDays();
  long hours = duration.minusDays(days).toHours();
  long minutes = duration.minusHours(duration.toHours()).toMinutes();
  return format("%dd %dh %dm", days, hours, minutes);
}

代码示例来源:origin: edu.stanford.nlp/stanford-corenlp

public static String elapsedTime(Date d1, Date d2){
 try{
  Duration period = Duration.between(d1.toInstant(), d2.toInstant());
  // Note: this will become easier with Java 9, using toDaysPart() etc.
  long days = period.toDays();
  period = period.minusDays(days);
  long hours = period.toHours();
  period = period.minusHours(hours);
  long minutes = period.toMinutes();
  period = period.minusMinutes(minutes);
  long seconds = period.getSeconds();
  return days + " days, " + hours + " hours, " + minutes + " minutes, " + seconds + " seconds";
 } catch(java.lang.IllegalArgumentException e) {
  log.warn(e);
 }
 return "";
}

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

Duration durationMinusDays = absDuration.minusDays(days);
if (durationMinusDays.getSeconds() != 0) {
  int hours = (int) durationMinusDays.getSeconds() / (60 * 60);

代码示例来源:origin: org.mnode.ical4j/ical4j

Duration durationMinusDays = absDuration.minusDays(days);
if (durationMinusDays.getSeconds() != 0) {
  int hours = (int) durationMinusDays.getSeconds() / (60 * 60);

代码示例来源:origin: com.microsoft.rest.v2/client-runtime

builder.append(days);
builder.append('D');
duration = duration.minusDays(days);

代码示例来源:origin: Azure/azure-service-bus-java

remainingTime = duration.minusDays(days);

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

Duration toEvening = Duration.between(evening, time);
if(fromMorning.isNegative()) toEvening=toEvening.plusDays(1);
else if(!toEvening.isNegative()) fromMorning=fromMorning.minusDays(1);
l1.setText(format(fromMorning, "morning"));
l2.setText(format(toEvening, "evening"));

代码示例来源:origin: kiegroup/optaweb-employee-rostering

public ShiftTemplate(Integer rotationLength, ShiftTemplateView shiftTemplateView, Spot spot, Employee rotationEmployee) {
  super(shiftTemplateView);
  this.spot = spot;
  this.rotationEmployee = rotationEmployee;
  this.startDayOffset = (int) (shiftTemplateView
      .getDurationBetweenRotationStartAndTemplateStart()
      .toDays());
  this.startTime = LocalTime.ofSecondOfDay(shiftTemplateView
                           .getDurationBetweenRotationStartAndTemplateStart()
                           .minusDays(startDayOffset)
                           .getSeconds());
  int endDayAfterStartDay = ((int) (shiftTemplateView
      .getDurationBetweenRotationStartAndTemplateStart()
      .plus(shiftTemplateView.getShiftTemplateDuration())
      .toDays()));
  this.endTime = LocalTime.ofSecondOfDay(shiftTemplateView
                          .getDurationBetweenRotationStartAndTemplateStart()
                          .plus(shiftTemplateView.getDurationOfTimeslot())
                          .minusDays(endDayAfterStartDay)
                          .getSeconds());
  this.endDayOffset = endDayAfterStartDay % rotationLength;
}

代码示例来源:origin: org.jdbi/jdbi3-postgres

@Override
  public Argument build(Duration duration, ConfigRegistry config) {
    Duration d = duration;
    final boolean isNegative = d.isNegative();
    if (isNegative) {
      d = d.negated();
    }
    final long days = d.toDays();
    if (days > Integer.MAX_VALUE) {
      throw new IllegalArgumentException(
          String.format("duration %s too large to be represented unambiguously as postgres interval",
              d));
    }
    d = d.minusDays(days);
    final int hours = (int) d.toHours();
    d = d.minusHours(hours);
    final int minutes = (int) d.toMinutes();
    d = d.minusMinutes(minutes);
    if (d.getNano() % 1000 != 0) {
      throw new IllegalArgumentException(
          String.format("duration %s too precise to represented as postgres interval", d));
    }
    double seconds = d.getSeconds() + d.getNano() / 1e9;
    final PGInterval interval = new PGInterval(0, 0, (int) days, hours, minutes, seconds);
    if (isNegative) {
      interval.scale(-1);
    }
    return ObjectArgument.of(interval, Types.OTHER);
  }
}

相关文章