java.time.Duration 如何计算 toDays()?

How does java.time.Duration calculate toDays()?

所以 java 关于这个的文档非常稀疏:

public long toDays()

Gets the number of days in this duration. This returns the total number of days in the duration by dividing the number of seconds by 86400. This is based on the standard definition of a day as 24 hours.

This instance is immutable and unaffected by this method call.

Returns: the number of days in the duration, may be negative

直截了当,但是这是做什么的?

// set duration to 36 hours
Duration duration = Duration.parse("PT36H");

// get days in duration
Long daysInDuration = duration.toDays();

System.out.println(daysInDuration);

是圆圆的,还是只是发言?我倾向于由它发言...

public long toDays() {
  return seconds / SECONDS_PER_DAY;
}

它将 long 除以 int 并将其分配给 long,因此这里没有智能舍入。标准整数除法。