package com.pj.common.core.utils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Locale;
import java.text.DateFormat;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
/**
 * @Author Mechrevo
 * @Date 2023 08 03 10 51
 **/

public class DateUtil {

        public static ThreadLocal<DateFormat> chinaDateSDF = new ThreadLocal<DateFormat>() {

            @Override
            protected DateFormat initialValue() {
                SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
                return df;

            }
        };

        /**
         * 获取日期yyyy-MM-dd格式字符串
         *
         * @param date
         * @param locale
         * @return
         */
        public static String dateToStr(Date date, Locale locale) {
            if (locale == null) {

            }
            return chinaDateSDF.get().format(date);
        }

        /**
         * 将长时间格式字符串转换为时间 yyyy-MM-dd HH:mm:ss
         *
         * @param strDate
         * @return
         */
        public static Date strToDateLong(String strDate) {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            ParsePosition pos = new ParsePosition(0);
            Date strtodate = formatter.parse(strDate, pos);
            return strtodate;
        }


}
