package com.casic.dcms.utils;

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

/**
 * @author : Pengxh
 * @time : 2021/4/15 16:54
 * @email : 290677893@qq.com
 **/
public class TimeOrDateUtil {
    private static final String TAG = "TimeOrDateUtil";
    private static SimpleDateFormat dateFormat;

    /**
     * 时间戳转年月日时分秒
     */
    public static String timestampToCompleteDate(long millSeconds) {
        dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        return dateFormat.format(new Date(millSeconds));
    }

    /**
     * 时间戳转年月日
     */
    public static String timestampToDate(long millSeconds) {
        dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
        return dateFormat.format(new Date(millSeconds));
    }

    /**
     * 时间戳转年月
     */
    public static String timestampToYearMonth(long millSeconds) {
        dateFormat = new SimpleDateFormat("yyyy年MM月", Locale.CHINA);
        return dateFormat.format(new Date(millSeconds));
    }

    /**
     * 时间戳转时分秒
     */
    public static String timestampToTime(long millSeconds) {
        dateFormat = new SimpleDateFormat("HH:mm:ss", Locale.CHINA);
        return dateFormat.format(new Date(millSeconds));
    }

    /**
     * 时间戳转时分
     */
    public static String minuteToTime(long millSeconds) {
        dateFormat = new SimpleDateFormat("HH:mm", Locale.CHINA);
        return dateFormat.format(new Date(millSeconds));
    }

    /**
     * 时间戳转分秒
     */
    public static String millsToTime(long millSeconds) {
        dateFormat = new SimpleDateFormat("mm:ss", Locale.CHINA);
        return dateFormat.format(new Date(millSeconds));
    }
}
