package com.yuchen.saas.park.service.util;

import java.util.Calendar;
import java.util.Date;

/**
 * 时间处理方法
 */
public class ParkDateUtils {
    /**
     * 获取当月第一天(00:00:00)
     * @return
     */
    public static Date getThisMonthFirstDay() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        //将小时至0
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        //将分钟至0
        calendar.set(Calendar.MINUTE, 0);
        //将秒至0
        calendar.set(Calendar.SECOND, 0);
        //将毫秒至0
        calendar.set(Calendar.MILLISECOND, 0);
        //获得当前月第一天
        Date startDate = calendar.getTime();

        return startDate;
    }

    /**
     * 根据当前时间获取当前月
     * @return 月份
     */
    public static int getCurrentMonth(Date newDate) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(newDate);
        return calendar.get(Calendar.MONTH) + 1;
    }

    /**
     * 根据时间获取上一月月份
     * @return 月份
     */
    public static int getLastMonth(Date newDate) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(newDate);
        calendar.add(Calendar.MONTH, -1);
        return calendar.get(Calendar.MONTH) + 1;
    }

    /**
     * 根据日期获取日期上一年年份
     * @return 年份
     */
    public static int getLastYear(Date newDate) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(newDate);
        calendar.add(Calendar.YEAR, -1);
        return calendar.get(Calendar.YEAR);
    }


}
