본문 바로가기

JAVA

[JAVA] 현재날짜, 일주일전날짜, 한달전날짜 계산

반응형

 

날짜 산출 예제


public void dateCalcEx(int delayTime){

	DecimalFormat df = new DecimalFormat("00");
	Calendar currentCalendar = Calendar.getInstance();


	//현재 날짜 구하기
	String strYear = Integer.toString(currentCalendar.get(Calendar.YEAR));
	String strMonth = df.format(currentCalendar.get(Calendar.MONTH) + 1);
	String strDay = df.format(currentCalendar.get(Calendar.DATE));
	String strDate = strYear + strMonth + strDay;


	//일주일 전 날짜 구하기
	currentCalendar.add(currentCalendar.DATE, -7);
	String strYear7 = Integer.toString(currentCalendar.get(Calendar.YEAR));
	String strMonth7 = df.format(currentCalendar.get(Calendar.MONTH) + 1);
	String strDay7 = df.format(currentCalendar.get(Calendar.DATE));
	String strDate7 = strYear7 + strMonth7 + strDay7;


	//한달 전 날짜 구하기
	currentCalendar.add(currentCalendar.MONTH, -1);
	String strYear31 = Integer.toString(currentCalendar.get(Calendar.YEAR));
	String strMonth31 = df.format(currentCalendar.get(Calendar.MONTH) + 1);
	String strDay31 = df.format(currentCalendar.get(Calendar.DATE));
	String strDate31 = strYear31 + strMonth31 + strDay31;

}

 

 

 

 

반응형