package J20250808.localDateTime;

import java.time.Duration;
import java.time.LocalDateTime;

/**
 * @author WanJl
 * @version 1.0
 * @title Demo06_DurationTest
 * @description
 * @create 2025/8/8
 */
public class Demo06_DurationTest {
    public static void main(String[] args) {
        LocalDateTime localDateTime01 = LocalDateTime.of(2020, 1, 1, 15, 15, 25);
        LocalDateTime localDateTime02 = LocalDateTime.of(2028, 1, 1, 15, 15, 25);
        //计算两个"时间"的间隔     public static Duration between(开始时间,结束时间)
        Duration duration = Duration.between(localDateTime01, localDateTime02);
        System.out.println(duration);   //PT70128H
        //获得此时间间隔的天数       public long toDays()
        System.out.println(duration.toDays());
        //获得此时间间隔的小时       public long toHours()
        System.out.println(duration.toHours());
        //获得此时间间隔的分钟       public long toMinutes()
        System.out.println(duration.toMinutes());
        //获得此时间间隔的秒       public long toSeconds()
        System.out.println(duration.getSeconds());
        //获得此时间间隔的毫秒      public int toMillis()
        System.out.println(duration.toMillis());
        //获得此时间间隔的纳秒      public int toNanos()
        System.out.println(duration.toNanos());

    }
}
