package cn.hmsoft.ltc.common.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import cn.hmsoft.ltc.model.Subject;

public class DateUtil {

	private static DateFormat format1 = new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
	
	public static String formatToString(Date date) {
		if (date == null)
			return "";
		return format1.format(date);
	}
	
	public static Date toDate(String strDate) {
		if (StringUtils.isNotEmpty(strDate)) {
			try {
				return format1.parse(strDate);
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		return null;
	}
	
	/**
	 * 时间格式转换成年月日
	 * @param strDate  时间
	 * @return
	 */
	public static String stringFormat(String strDate) {
		String str = "";
		str = strDate.substring(2,10);
		String strYear = str.substring(0,2);
		String strMonth = str.substring(3,5);
		String strDay = str.substring(6, 8);
		str = strYear+"年"+strMonth+"月"+strDay+"日";
		return str;
	}
	
	public static void main(String[] args) {
		String strDate = "2019-09-20 04:15:42";
		String str = DateUtil.stringFormat(strDate);
		System.out.println(str);
	}
}
