주어진 시간(String)이 현재 시간 이후에 있습니까?

1028 단어 String
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TestDate {
	public static void main(String[] args) {
		{

			if (timeCompare()) {
				System.out.print("    ");
			}
			;

		}
	}

	/**
	 * 
	 */
	private static boolean timeCompare() {
		try {//        

			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
			String currenttime = df.format(new Date());
			currenttime = currenttime.substring(11, 19);

			SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
			String sendtime = "10:30:00--12:30:00".substring(10, 17);
			Date date = sdf.parse(sendtime);
			Date date2 = sdf.parse(currenttime);

			System.out.print("  " + date.toString());//      1970    
														//            
			System.out.print("  " + date2.toString());

			if (date.after(date2)) {
				return true;
			}
		} catch (ParseException e) {

			e.printStackTrace();

		}
		return false;

	}
}

좋은 웹페이지 즐겨찾기