자바 시간 비교

1293 단어
import java.text.*;
import java.util.*;

public static void main(String arg[])
{
   String date = "";   
   SimpleDateFormat  sdf=  new   SimpleDateFormat("yyyy-MM-dd");   
   java.util.Date   dd     =   Calendar.getInstance().getTime();   
	    date = sdf.format(dd);
	   System.out.println(date);
    boolean flag = isDateBefore(date+" 09:01:00");
	  System.out.println(flag);
}

public static boolean isDateBefore(String date2)
{
      try{
	Date date1 = new Date();
	DateFormat df = DateFormat.getDateTimeInstance();
	System.out.println(date1.before(df.parse(date2)));
	return date1.before(df.parse(date2)); 
	}catch(ParseException e){
	System.out.print(e.getMessage());
	return false;
	}
	}
}

public static boolean isDateAfter(String date2){
	try{
		Date date1 = new Date();
		DateFormat df = DateFormat.getDateTimeInstance();
		System.out.println(date1.after(df.parse(date2)));
		return date1.after(df.parse(date2)); 
	}catch(ParseException e){
		System.out.print(e.getMessage());
		return false;
	}
}

                       

좋은 웹페이지 즐겨찾기