package org.springblade.modules.app.utils;

import lombok.extern.slf4j.Slf4j;

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


@Slf4j
public class DateUtils {

    /**
     *
     * @Description: 获取上个月环比日期
     * @param
     * @return String
     * @throws
     * @author
     * @createtime
     */
    public static String getHbDate(String currentDate) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;
        try {
            date = sdf.parse(currentDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar ca = Calendar.getInstance();//得到一个Calendar的实例
        ca.setTime(date); //设置时间为当前时间
        ca.add(Calendar.MONTH, -1); //月份减1
        return sdf.format(ca.getTime());
    }
    /**
     *
     * @Description: 获取去年同比日期
     * @param
     * @return String
     * @throws
     * @author
     * @createtime
     */
    public static String getTbDate(String currentDate) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;
        try {
            date = sdf.parse(currentDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar ca = Calendar.getInstance();//得到一个Calendar的实例
        ca.setTime(date); //设置时间为当前时间
        ca.add(Calendar.YEAR, -1); //年份减1
        return sdf.format(ca.getTime());
    }

}
