java.time.Duration.abs() 方法示例


java.time.Duration.abs() 方法示例

package com.codingdict;

import java.time.Duration;
import java.time.LocalTime;
import java.time.temporal.ChronoUnit;

public class DurationDemo {
   public static void main(String[] args) {

      Duration duration = Duration.between(LocalTime.NOON,LocalTime.MIN);  
      System.out.println(duration.get(ChronoUnit.SECONDS));    

      Duration absDuration = duration.abs();
      System.out.println(absDuration.get(ChronoUnit.SECONDS));    
   }
}