package com.lovecoding.day14.api02;

import org.junit.Test;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

public class TestDate01 {

    //Locale
    @Test
    public void test05() throws Exception {
        Calendar c1 = Calendar.getInstance();

        System.out.println(c1.get(Calendar.YEAR));
        System.out.println(c1.get(Calendar.MONDAY));
        System.out.println(c1.get(Calendar.DAY_OF_MONTH));
        System.out.println(c1.get(Calendar.DAY_OF_WEEK));

        //add
        System.out.println(c1.getTime());
        c1.add(Calendar.YEAR,-1);
        System.out.println(c1.getTime());

        System.out.println(c1.getTime());
        c1.add(Calendar.MONTH,1);
        System.out.println(c1.getTime());

        //set
        c1.set(Calendar.YEAR,1980);
        System.out.println(c1.getTime());



    }
    //Locale
    @Test
    public void test04() throws Exception {

        Locale[] availableLocales = Locale.getAvailableLocales();

        for (Locale availableLocale : availableLocales) {
            System.out.println(availableLocale);
        }

        System.out.println("----------------");
        System.out.println(Locale.CHINA);

    }

    //`TimeZone`
    @Test
    public void test03() throws Exception {
        String[] availableIDs = TimeZone.getAvailableIDs();

        for (String availableID : availableIDs) {
            System.out.println(availableID);
        }

        //Asia/Shanghai
        TimeZone timeZone = TimeZone.getTimeZone("Asia/Shanghai");
        System.out.println(timeZone);
    }

    //SimpleDateFormat
    @Test
    public void test02() throws Exception {
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");

        //时间转字符串
        Date date1 = new Date();
        //转换
        String strDate1 = sdf1.format(date1);
        System.out.println(strDate1);

        //字符串转时间
        String strDate2 = "2023/02/12 15:33:33";
        Date parse = sdf2.parse(strDate2);
        System.out.println(parse);

        //时间
        System.out.println(sdf2.format(parse));


    }

    @Test
    public void test01() throws InterruptedException {
        //Date
        Date date1 = new Date();
        System.out.println(date1);

        Thread.sleep(10000);
        //时间戳
        long time = new Date().getTime();
        System.out.println(time);

        //时间戳 转 Date
        Date date2 = new Date(time);
        System.out.println(date2);

    }
}
