이 블로그 검색

2010년 12월 14일 화요일

Calendar

cal.getTime ( )  : 캘린더에 해당하는 Date객체 return





    //공고일이 2010. 12. 03일 일 경우 만20세미만 날짜 가져오기 : 1990.12.04
    //  (1990.12.04이후 출생자)
    Calendar cal = Calendar.getInstance ( );
   //공고일로 설정
    cal.set(2010,12-1,03);
  
    cal.add ( Calendar.YEAR, -20 ); //20년 전....
    cal.add ( Calendar.DATE, +1 ); //1일 +
    String threeChildDate = new java.text.SimpleDateFormat("yyyy.MM.dd").format(cal.getTime());








현재날짜에서 2달전의 날짜를 구하기

Calendar cal = Calendar.getInstance ( );//오늘 날짜를 기준으루..
cal.add ( cal.MONTH, -2 ); //2개월 전....
System.out.println ( cal.get ( cal.YEAR ) );
System.out.println ( cal.get ( cal.MONTH ) + 1 );
System.out.println ( cal.get ( cal.DATE ) );





특정일을 입력받아 해당 월의 마지막 날짜를 구하는 간단한 예제.(달은 -1 해준다.)...윤달 30일 31일 알아오기.


Calendar cal = Calendar.getInstance ( );
cal.set ( Integer.parseInt ( args[0] ), Integer.parseInt ( args [1] ) - 1, Integer.parseInt ( args [2] ) );
SimpleDateFormat dFormat = new SimpleDateFormat ( "yyyy-MM-dd" );
System.out.println ( "입력 날짜 " + dFormat.format ( cal.getTime ( ) ) );
System.out.println ( "해당 월의 마지막 일자 : " + cal.getActualMaximum ( Calendar.DATE ) );

댓글 없음:

댓글 쓰기