package com.erp.common;
import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date;
/**************************************** * @프로젝트 : Digital2u Community * @파일명 : ThreeMonthAgo.java * @생성일 : 2022. 5. 28. * @작성자 : Charlotte * @프로그램 설명 : ***************************************** * @변경이력 : ****************************************/ public class ThreeMonthAgo {
// 메인 public static void main(String[] args) throws Exception { Date date = new Date(); SimpleDateFormat sdformat = new SimpleDateFormat("yyyyMMdd"); Date before3Mon = addMonth(date,-3); // ******************************************* -3 String today = sdformat.format(date); System.out.println("오늘 날짜 : " + today); String before3Months = sdformat.format(before3Mon); System.out.println("3개월전 날짜 : " + before3Months); }
// X개월 날짜 추출 public static Date addMonth(Date date, int months) { Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.add(Calendar.MONTH, months); return cal.getTime(); } }