package com.friday.custody.service.trustService.citicZhongXin.utils;

import lombok.extern.slf4j.Slf4j;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;

/**
 * @Description
 * @Author wulifeng
 * @Date: 2022/4/12
 */
@Slf4j
public class DateTimeTransUtil {
    public static String transDateFormat(String originFormat,String targetFormat,String value){
        try{
            log.info("DateTimeTransUtil_transFormat_originFormat={},targetFormat={},value={}",originFormat,targetFormat,value);
            DateTimeFormatter originFormatter = DateTimeFormatter.ofPattern(originFormat);
            DateTimeFormatter targetFormatter = DateTimeFormatter.ofPattern(targetFormat);
            LocalDate realDateTime = LocalDate.parse(value, originFormatter);
            String format = targetFormatter.format(realDateTime);
            return format;
        }catch (Exception e){
            log.error("DateTimeTransUtil_transFormat转换时间失败",e);
            return null;
        }

    }

    public static void main(String[] args) {
        String  ori = "yyyyMMdd";
        String target = "yyyy-MM-dd";
        String value = "20191016";
        System.out.println(transDateFormat(ori, target, value));
    }
}
