比较日期

package com.luodada.trans.soa.busi.web;

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

public class JudgeDate {
	
	/**
	 * 
	 * 比较两个日期
	 * @author luochao
	 * @date 2009-8-24
	 * @param date1
	 * @param date2
	 * @return boolean
	 */
	public static boolean isDateBefore(String date1, String date2) {
		try {
			DateFormat df = DateFormat.getDateTimeInstance();
			return df.parse(date1).before(df.parse(date2));
		} catch (ParseException ex) {
			System.out.print("[SYS]" + ex.getMessage());
			return false;
		}
	}
	
	/**
	 * 
	 * 指定日期与当前日期比较
	 * @author luochao
	 * @date 2009-8-24
	 * @param date2
	 * @return boolean
	 */
	public static boolean isDateBefore(String date2) {
		try {
			Date date1 = new Date();
			DateFormat df = DateFormat.getDateTimeInstance();
			return date1.before(df.parse(date2));
		} catch (ParseException ex) {
			System.out.print("[SYS]" + ex.getMessage());
			return false;
		}
	}
	
	public static void main(String[] args) {
		boolean flag = isDateBefore("2009-08-24 12:30:56", "2009-08-24 16:15:35");
		System.out.println(flag);
		flag = isDateBefore("2008-08-08 20:08:08");
		System.out.println(flag);
	}
}

 

你可能感兴趣的:(java,Web,SOA)