package com.yfyy.yingtan.util;

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

/**
 * date工具类
 */
public class MyDateUtil {

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

    public static String yyyy_mm_dd = "yyyy-MM-dd";

    public static String mmdd = "MMdd";

    public static String dd = "dd";

    public static String mm_dd_hh_mm = "MM-dd HH:mm";
    public static String hh_mm = "HH:mm";


    /**
     * 将Date转化为指定格式的字符串
     *
     * @param date time
     * @param flag 格式
     * @return 时间字符串
     */
    public static String toString(Date date, String flag) {
        SimpleDateFormat formatter = new SimpleDateFormat(flag, Locale.CHINA);
        String sdf = "";
        try {
            if (date != null) {
                sdf = formatter.format(date);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return sdf;
    }

    /**
     * 将Date转化为指定格式的字符串
     * yyyy_mm_dd_hh_mm_ss= "yyyy-MM-dd HH:mm:ss";
     *
     * @param date time
     * @return 时间字符串
     */
    public static String toStandardString(Date date) {
        SimpleDateFormat formatter = new SimpleDateFormat(yyyy_mm_dd_hh_mm_ss, Locale.CHINA);
        String sdf = "";
        try {
            if (date != null) {
                sdf = formatter.format(date);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return sdf;
    }

}
