package com.huimv.modular.utils.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

public class DateUtil {

    public DateUtil() {
    }

    public static String getNowWithDigital() {
        Date now = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(now).replaceAll("-", "").replaceAll(" ", "").replaceAll(":", "");
    }


    public static String buildDateTimeString(String formatContent) {
        String year = formatContent.substring(0, 4);
        String month = formatContent.substring(4, 6);
        String day = formatContent.substring(6, 8);
        String hour = formatContent.substring(8, 10);
        String minute = formatContent.substring(10, 12);
        String seconds = formatContent.substring(12, 14);
        StringBuilder dateTimeSb = new StringBuilder();
        return dateTimeSb.append(year).append("-").append(month).append("-").append(day).append(" ").append(hour).append(":").append(minute).append(":").append(seconds).toString();
    }

    public static String buildDateString(String formatContent) {
        String year = formatContent.substring(0, 4);
        String month = formatContent.substring(4, 6);
        String day = formatContent.substring(6, 8);
        String dateTime = year + "-" + month + "-" + day;
        return dateTime;
    }

    public static String formatDateTime(String date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:SS");
        return sdf.format(date);
    }

    public static Date parseDateTime(String date) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.parse(date);
    }

    public String getToday() {
        DateFormat df3 = DateFormat.getDateInstance(2, Locale.CHINA);
        return df3.format(new Date());
    }

    public static void main(String[] args) {
         DateUtil dateUtil=new DateUtil();
        System.out.println(dateUtil.getToday());
         String a = dateUtil.getToday();
        System.out.println(a);



    }

    public String formatDate(Date date) {
        DateFormat df3 = DateFormat.getDateInstance(2, Locale.CHINA);
        return df3.format(date);
    }



    public String beforeTime(int times) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar calendar = Calendar.getInstance();
        calendar.set(11, calendar.get(11) - times);
        String endTime = sdf.format(calendar.getTime());
        System.out.println("提前3小时：" + endTime);
        return endTime;
    }
}
