package com.xhpc.common.util;

import cn.hutool.core.date.DateTime;

import java.util.Calendar;
import java.util.Date;

/**
 * 进行日期处理的工具类
 *
 * @author WH
 * @date 2022/1/15 15:59
 * @since version-1.0
 */
@SuppressWarnings("all")
public class MyDateUtil {

    public static final String DATE_FORMAT_DATE_TIME = "yyyy-MM-dd HH:mm:ss";

    public static void main(String[] args) {

        System.out.println(getCurrentDateStr());
    }

    /**
     * 以xxxx年x月xx日 星期x的字符串格式展示当前时间
     *
     * @author WH
     * @date 2022/1/15 16:15
     * @since version-1.0
     */
    public static String getCurrentDateStr() {

        Calendar now = Calendar.getInstance();
        int year = now.get(Calendar.YEAR);
        int month = now.get(Calendar.MONTH) + 1;
        int day = now.get(Calendar.DAY_OF_MONTH);
        String dayNames[] = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
        int dayOfWeek = now.get(Calendar.DAY_OF_WEEK) - 1;
        if (dayOfWeek < 0) dayOfWeek = 0;
        String week = dayNames[dayOfWeek];
        String nowDateStr = year + "年" + month + "月" + day + "日 " + week;

        return nowDateStr;

    }

    /**
     * 获取表示所传入的Date对象的Calendar对象
     *
     * @param date 要转换的Date对象
     * @return 表示所传入的Date对象的Calendar对象
     * @author WH
     * @date 2022/1/15 16:11
     * @since version-1.0
     */
    public static Calendar getCalendar(Date date) {

        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c;
    }

    /**
     * 获取一个yyyy-MM-dd HH:mm:ss格式的当前时间字符串
     *
     * @author WH
     * @date 2022/1/15 16:04
     * @since version-1.0
     */
    public static String getCurrentDateStrInYyyyMmDdHhMmSsFormat() {

        return DateTime.now().toString(DATE_FORMAT_DATE_TIME);
    }

}
