package com.mini.capi.utils;


import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Locale;

public class vDate {


    private static final DateTimeFormatter DEFAULT_FMT =
            DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    private static final SimpleDateFormat DEFAULT_SDF =
            new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z", Locale.ENGLISH);

    public static String toStr(LocalDateTime dateTime) {
        return dateTime.format(DEFAULT_FMT);
    }

    /**
     * LocalDateTime → String（自定义格式）
     */
    public static String toStr(LocalDateTime dateTime, String pattern) {
        return dateTime.format(DateTimeFormatter.ofPattern(pattern));
    }

    public static String getNow() {
        Date date = new Date();
        return DEFAULT_SDF.format(date);
    }


    public static String getDockerCreate(String createAt) {
        try {
            String cleaned = createAt.replace(" CST", "");
            // 定义格式
            Date date = sdf.parse(cleaned);
            return DEFAULT_SDF.format(date);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return getNow();
        }
    }
}
