package com.lovecoding.day16.api01;

import org.junit.Test;

import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
import java.time.format.DateTimeFormatter;

public class TestDate {


    @Test
    public void test03(){

        LocalDateTime localDateTime = LocalDateTime.now();

        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss");
        String format = dateTimeFormatter.format(localDateTime);
        System.out.println(format);

    }

    @Test
    public void test02(){
        LocalDateTime localDate1 = LocalDateTime.now();
        LocalDateTime localDate2 = LocalDateTime.of(2008,8,8,8,8,8);

        Duration between = Duration.between(localDate2, localDate1);
        long seconds = between.getSeconds();
        System.out.println(seconds);


    }
    @Test
    public void test01(){
        //Period和Duration
        LocalDate localDate1 = LocalDate.now();
        LocalDate localDate2 = LocalDate.of(2008,8,8);

        //日期间隔
        Period between = Period.between(localDate2, localDate1);

        System.out.println(between.getDays());//相差天数
        System.out.println(between.getYears());//相差年
        System.out.println(between.getMonths());//相差月

        long l = between.toTotalMonths();
        System.out.println(l);

    }


}
