java.time.OffsetDateTime.until()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(2.8k)|赞(0)|评价(0)|浏览(187)

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

OffsetDateTime.until介绍

[英]Calculates the period between this date-time and another date-time in terms of the specified unit.

This calculates the period between two date-times in terms of a single unit. The start and end points are this and the specified date-time. The result will be negative if the end is before the start. For example, the period in days between two date-times can be calculated using startDateTime.until(endDateTime, DAYS).

The Temporal passed to this method must be an OffsetDateTime. If the offset differs between the two date-times, the specified end date-time is normalized to have the same offset as this date-time.

The calculation returns a whole number, representing the number of complete units between the two date-times. For example, the period in months between 2012-06-15T00:00Z and 2012-08-14T23:59Z will only be one month as it is one minute short of two months.

This method operates in association with TemporalUnit#between. The result of this method is a long representing the amount of the specified unit. By contrast, the result of between is an object that can be used directly in addition/subtraction:

long period = start.until(end, MONTHS);   // this method 
dateTime.plus(MONTHS.between(start, end));      // use in plus/minus

The calculation is implemented in this method for ChronoUnit. The units NANOS, MICROS, MILLIS, SECONDS, MINUTES, HOURS and HALF_DAYS, DAYS, WEEKS, MONTHS, YEARS, DECADES, CENTURIES, MILLENNIA and ERAS are supported. Other ChronoUnit values will throw an exception.

If the unit is not a ChronoUnit, then the result of this method is obtained by invoking TemporalUnit.between(Temporal, Temporal)passing this as the first argument and the input temporal as the second argument.

This instance is immutable and unaffected by this method call.
[中]

代码示例

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

private static void binaryEncodeTIMESTAMPTZ(OffsetDateTime value, ByteBuf buff) {
 buff.writeLong(-value.until(OFFSET_DATE_TIME_EPOCH, ChronoUnit.MICROS));
}

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

private static void binaryEncodeTIMESTAMPTZ(OffsetDateTime value, ByteBuf buff) {
 buff.writeLong(-value.until(OFFSET_DATE_TIME_EPOCH, ChronoUnit.MICROS));
}

代码示例来源:origin: SonarSource/sonarlint-core

private TelemetryPayload createPayload(TelemetryData data, boolean usesConnectedMode, boolean usesSonarCloud) {
 OffsetDateTime systemTime = OffsetDateTime.now();
 long daysSinceInstallation = data.installTime().until(systemTime, ChronoUnit.DAYS);
 TelemetryAnalyzerPerformancePayload[] analyzers = TelemetryUtils.toPayload(data.analyzers());
 return new TelemetryPayload(daysSinceInstallation, data.numUseDays(), product, version,
  usesConnectedMode, usesSonarCloud, systemTime, data.installTime(), analyzers);
}

代码示例来源:origin: com.github.seratch/java-time-backport

return dateTime.until(end.dateTime, unit);
} else {
  return toOffsetDateTime().until(end.toOffsetDateTime(), unit);

相关文章