src/com/util/DateUtils.java

(完整代码) 1KB

package com.util;

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

public class DateUtils {

	/**
	 * 字符串转日期
	 * @param strDate
	 * @param strFormat
	 * @return
	 */
	public static Date formatStr2Date(String strDate,String strFormat){
		Date retValue = null;
		try{
			SimpleDateFormat sdf = new SimpleDateFormat(strFormat);
			retValue =  sdf.parse(strDate);
		}catch(ParseException e){
			e.printStackTrace();
		}
		return retValue;
	}
	
	/**
	 * 日期转字符串
	 * @param date
	 * @param strFormat
	 * @return
	 */
	public static String formatDate2Str(Date date,String strFormat){
		String retValue = null;
		
		SimpleDateFormat sdf = new SimpleDateFormat(strFormat);
		retValue =  sdf.format(date);
		
		return retValue;
	
	}
	
	/**
	 * 获取两个日期之间相差的天数
	 * @param et
	 * @param st
	 * @return
	 */
	public static int getTwoDateDays(Date et,Date st){
		int day = 0;
		day = (int)((et.getTime()-st.getTime())/(24*60*60*1000));
		return day;
	}
}

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读 AI

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。