package com.sdut.labex.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * File: FormatDate
 * Created: 2023/6/17
 * Author: springforest
 * Description:
 */

public class FormatDate {
    public static String formatDate(Date date) {
        SimpleDateFormat dateFormat;
        if (isMidnightTime(date)) {
            dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        } else {
            dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        }
        return dateFormat.format(date);
    }

    private static boolean isMidnightTime(Date date) {
        SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
        String timeString = timeFormat.format(date);
        return timeString.equals("00:00:00");
    }
}
