package com.hzjt.util;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

/**
 * ʱ���ʽת���� 2019.10.23
 * @author cp
 */
public class DateUtils {
    private static final Logger log = LoggerFactory.getLogger(DateUtils.class);
    public static String getDateString(Date date) {
         SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        log.info("date  timezone:{}",formatter.getTimeZone()) ;
        formatter.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
         log.info("date  timezone:{}",formatter.getTimeZone()) ;
         String dateString = formatter.format(date);
         return dateString ;
    }

    public static String getDateStringNoSign(Date date) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
        log.info("date  timezone:{}",formatter.getTimeZone()) ;
        formatter.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
        log.info("date  timezone:{}",formatter.getTimeZone()) ;
        String dateString = formatter.format(date);
        return dateString ;
    }

    public static String formatCurrDayNoSign() {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
        log.info("date  timezone:{}",formatter.getTimeZone()) ;
        formatter.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
        log.info("date  timezone:{}",formatter.getTimeZone()) ;
        String dateString = formatter.format(new  Date());
        return dateString ;
    }
    public static Date Parsedate(String datestr) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        log.info("date  timezone:{}",formatter.getTimeZone()) ;
        formatter.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
        log.info("date  timezone:{}",formatter.getTimeZone()) ;
        try {
            Date dateString = formatter.parse(datestr);
            return dateString ;
        }catch (Exception ex){
            return null;
        }
    }

}
