package com.chinaitop.depot.intelligent.utils;

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

public class DateUtils {

    public static String startTime = " 00:00:00";
    public static String endTime = " 23:59:59";
    //字符串转date
    public static Date stringToData(String str) {
        try {
            return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(str);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    //获取时间
    public static Date getDate() {
        return new Date();
    }

    //date转string
    public static String dateToString(Date time) {
        String dateString = null;
        try {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            dateString = formatter.format(time);
            return dateString;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    // 获取日期格式化
    public static String formatDate(Date date) {
        SimpleDateFormat dateTime = new SimpleDateFormat("yyyy-MM-dd");
        return dateTime.format(date);
    }

    // 获取日期格式化
    public static String getCurrentDate() {
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");//设置日期格式
        return df.format(new Date());
    }

    // 获取日期格式化
    public static String getNYR() {
        SimpleDateFormat dateTime = new SimpleDateFormat("yyyyMMdd");
        return dateTime.format(new Date());
    }

    //字符串转date
    public static Date stringToData(String str,String format) {
        try {
            return new SimpleDateFormat(format).parse(str);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
