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

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

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

Duration.minusHours介绍

[英]Returns a copy of this duration with the specified duration in hours subtracted.

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

代码示例

代码示例来源: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: it.rebase/rebot-uptime-service

/**
   * Returns the uptime in the following pattern: 0 Hora(s), 1 minuto(s) e 1 segundo(s).
   * Tip by Ingo
   */
  private String upTime() {
    Duration duration = Duration.ofMillis(ManagementFactory.getRuntimeMXBean().getUptime());
    long hours = duration.toHours();
    long minutes = duration.minusHours(hours).toMinutes();
    long seconds = duration.minusHours(hours).minusMinutes(minutes).getSeconds();
    return "<b>" + hours + "</b> Hours(s), <b>" + minutes + "</b> minute(s) and <b>" + seconds + "</b> Second(s)";
  }
}

代码示例来源:origin: it.tidalwave.accounting/it-tidalwave-accounting-model

@Nonnull
 public String format (final @Nonnull Duration duration)
  {
   final long hours = duration.toHours();
   final long minutes = duration.minusHours(hours).toMinutes();
   return String.format("%d:%02d", hours, minutes);
  }
}

代码示例来源:origin: com.neotys.neoload/neoload-project

protected static String convertToString(final Integer inputInMilliSecond) {
  if (inputInMilliSecond == null) return null;
  if (inputInMilliSecond <= 0) return ZERO;
  Duration duration = Duration.ofMillis(inputInMilliSecond);
  final long hours = duration.toHours();
  duration = duration.minusHours(hours);
  final long minutes = duration.toMinutes();
  duration = duration.minusMinutes(minutes);
  final long seconds = duration.getSeconds();
  duration = duration.minusSeconds(seconds);
  final long milliSeconds = duration.toMillis();
  final StringBuilder sb = new StringBuilder();
  if (hours != 0) {
    sb.append(hours).append(HOURS);
  }
  if (minutes != 0) {
    sb.append(minutes).append(MINUTES);
  }
  if (seconds != 0) {
    sb.append(seconds).append(SECONDS);
  }
  if (milliSeconds != 0) {
    sb.append(milliSeconds).append(MILLISECONDS);
  }
  return sb.toString();
}

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

if (durationMinusDays.getSeconds() != 0) {
  int hours = (int) durationMinusDays.getSeconds() / (60 * 60);
  int minutes = (int) durationMinusDays.minusHours(hours).getSeconds() / 60;
  int seconds = (int) durationMinusDays.minusHours(hours).minusMinutes(minutes).getSeconds();
  if (hours > 0) {
    if (seconds > 0) {

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

if (durationMinusDays.getSeconds() != 0) {
  int hours = (int) durationMinusDays.getSeconds() / (60 * 60);
  int minutes = (int) durationMinusDays.minusHours(hours).getSeconds() / 60;
  int seconds = (int) durationMinusDays.minusHours(hours).minusMinutes(minutes).getSeconds();
  if (hours > 0) {
    if (seconds > 0) {

代码示例来源: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: com.microsoft.rest.v2/client-runtime

builder.append(hours);
builder.append('H');
duration = duration.minusHours(hours);

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

remainingTime = duration.minusHours(hours);

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

Duration duration = Duration.ofMillis(runningTime);
long hours = duration.toHours();
duration = duration.minusHours(hours);
long minutes = duration.toMinutes();
duration = duration.minusMinutes(minutes);

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

duration = duration.minusHours(hours);
long mins = duration.toMinutes();
duration = duration.minusMinutes(mins);

代码示例来源:origin: reactiverse/reactive-pg-client

private static Interval binaryDecodeINTERVAL(int index, int len, ByteBuf buff) {
 Duration duration = Duration.of(buff.getLong(index), ChronoUnit.MICROS);
 final long hours = duration.toHours();
 duration = duration.minusHours(hours);
 final long minutes = duration.toMinutes();
 duration = duration.minusMinutes(minutes);
 final long seconds = NANOSECONDS.toSeconds(duration.toNanos());
 duration = duration.minusSeconds(seconds);
 final long microseconds = NANOSECONDS.toMicros(duration.toNanos());
 int days = buff.getInt(index + 8);
 int months = buff.getInt(index + 12);
 Period monthYear = Period.of(0, months, days).normalized();
 return new Interval(monthYear.getYears(), monthYear.getMonths(), monthYear.getDays(),
  (int) hours, (int) minutes, (int) seconds, (int) microseconds);
}

代码示例来源:origin: io.reactiverse/reactive-pg-client

private static Interval binaryDecodeINTERVAL(int index, int len, ByteBuf buff) {
 Duration duration = Duration.of(buff.getLong(index), ChronoUnit.MICROS);
 final long hours = duration.toHours();
 duration = duration.minusHours(hours);
 final long minutes = duration.toMinutes();
 duration = duration.minusMinutes(minutes);
 final long seconds = NANOSECONDS.toSeconds(duration.toNanos());
 duration = duration.minusSeconds(seconds);
 final long microseconds = NANOSECONDS.toMicros(duration.toNanos());
 int days = buff.getInt(index + 8);
 int months = buff.getInt(index + 12);
 Period monthYear = Period.of(0, months, days).normalized();
 return new Interval(monthYear.getYears(), monthYear.getMonths(), monthYear.getDays(),
  (int) hours, (int) minutes, (int) seconds, (int) microseconds);
}

代码示例来源: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);
  }
}

代码示例来源:origin: org.kie/kie-dmn-feel

{ BuiltInType.UNKNOWN, "duration( \"-P5DT4H23M55S\" )", Duration.ofDays( -5 ).minusHours( 4 ).minusMinutes( 23 ).minusSeconds( 55 ) },
{ BuiltInType.UNKNOWN, "duration( \"P23D\" )", Duration.ofDays( 23 ) },
{ BuiltInType.UNKNOWN, "duration( \"-P23D\" )", Duration.ofDays( -23 ) },

代码示例来源:origin: org.kie/kie-dmn-feel

{ BuiltInType.DURATION, "-P5DT4H23M55S", Duration.ofDays( -5 ).minusHours( 4 ).minusMinutes( 23 ).minusSeconds( 55 ) },
{ BuiltInType.DURATION, "P23D", Duration.ofDays( 23 ) },
{ BuiltInType.DURATION, "-P23D", Duration.ofDays( -23 ) },

代码示例来源:origin: org.kie/kie-dmn-feel

{ Duration.ofDays( -5 ).minusHours( 4 ).minusMinutes( 23 ).minusSeconds( 55 ), "-P5DT4H23M55S" },
{ Duration.ofDays( 23 ), "P23D" },
{ Duration.ofDays( -23 ), "-P23D" },

代码示例来源:origin: org.kie/kie-dmn-feel

{ Duration.ofDays( -5 ).minusHours( 4 ).minusMinutes( 23 ).minusSeconds( 55 ), "duration( \"-P5DT4H23M55S\" )" },
{ Duration.ofDays( 23 ), "duration( \"P23D\" )" },
{ Duration.ofDays( -23 ), "duration( \"-P23D\" )" },

相关文章