본문 바로가기
웹프로그래밍/Java

[JAVA] 년,월,일,시간,분으로 분리

by Seras 2017. 8. 2.
반응형
public int dateVil(String checkDate) {

	    //띄어쓰기를 구분으로 분리 (yyyy-mm-dd, HH:mm)
	    String checkYear = checkDate.split("\\s")[0];
	    String checkHour = checkDate.split("\\s")[1];
	    
	    //년,월,일,시간,분으로 분리
	    String year = checkYear.split("-")[0];
	    String month = checkYear.split("-")[1];
	    String day = checkYear.split("-")[2];
	    String hour = checkHour.split(":")[0];
	    String min = checkHour.split(":")[1];

	    //값 비교
	    int yearDate = Integer.parseInt(year);
	    int monthDate = Integer.parseInt(month);
	    int dayDate = Integer.parseInt(day);
	    int hourDate = Integer.parseInt(hour);
	    int minDate = Integer.parseInt(min);

	    int count = 0;

	    if (9999 < yearDate) {
	        count++;
	    } else if (monthDate > 12 || monthDate < 1) {
	        count++;
	    } else if (dayDate > 31 || dayDate < 1) {
	        count++;
	    } else if (hourDate > 23 || hourDate < 0) {
	        count++;
	    } else if (minDate > 59 || minDate < 0) {
	        count++;
	    }

	    return count;
	}


반응형