package com.casic.dcms.utils;

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

/**
 * @author : Pengxh
 * @time : 2021/4/15 16:54
 * @email : 290677893@qq.com
 **/
public class TimeOrDateUtil {
    private static final String TAG = "TimeOrDateUtil";
    private static final SimpleDateFormat allDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    private static final SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
    private static final SimpleDateFormat millsFormat = new SimpleDateFormat("mm:ss");

    /**
     * 时间戳转时间
     */
    public static String millsToTime(long millSeconds) {
        return millsFormat.format(new Date(millSeconds));
    }

    /**
     * 时间戳转日期
     */
    public static String rTimestampToDate(long millSeconds) {
        return dateFormat.format(new Date(millSeconds));
    }

    /**
     * 时间戳转时间
     */
    public static String timestampToTime(long millSeconds) {
        return timeFormat.format(new Date(millSeconds));
    }

    /**
     * 时间戳转详细日期时间
     */
    public static String timestampToDate(long millSeconds) {
        return allDateFormat.format(new Date(millSeconds));
    }

    /**
     * 时间转时间戳
     */
    public static long dateToTimestamp(String time) {
        try {
            return allDateFormat.parse(time).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0L;
    }

    /**
     * 获取当前日期
     */
    public static String getCurrentDate() {
        Calendar calendar = Calendar.getInstance();
        long today = calendar.getTimeInMillis();
        return rTimestampToDate(today);
    }
}
