자바 출력 달력

2276 단어
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;


public class MyDate {
	
	  public static void main(String[] args) {
	        MyDate date = new MyDate(); 
	        
	        Calendar calendar = Calendar.getInstance() ;
	        int month = calendar.get(Calendar.MONTH ) + 1 ;
	        calendar.set(Calendar.MONTH , month ) ; 
	        date.myCalendar( calendar.getTime() ) ; 
	    } 
	    //         
	    public void myCalendar(Date date) { 
	        GregorianCalendar now = new GregorianCalendar(); 
	        //         
	        //         
	        now.setTime(date); 
	        //             
	        int toDay = now.get(Calendar.DAY_OF_MONTH); 
	        //             
	        int month = now.get(Calendar.MONTH) ; 
	        //   now    1  
	        now.set(Calendar.DAY_OF_MONTH, 1); 
	        //   now         
	        int week = now.get(Calendar.DAY_OF_WEEK); 
	        //           
	        System.out.println(" \t \t \t \t \t \t ");
	        //              
	        for (int i = Calendar.SUNDAY; i < week; i++) { 
	            System.out.print("\t");  
	        } 
	        //         
	        while (now.get(Calendar.MONTH) == month) { 
	            int day = now.get(Calendar.DAY_OF_MONTH); 
	            //           ,  10         
	            if (day < 10) { 
	                //        ,      
	                if (day == toDay) { 
	                    System.out.print("▲" + day + "▲\t"); 
	                } else { 
	                    System.out.print(" " + day + "\t"); 
	                } 
	            } else { 
	                //        ,      
	                if (day == toDay) { 
	                    System.out.print("▲" + day + "▲\t"); 
	                } else { 
	                    System.out.print("" + day + "\t"); 
	                } 
	            }
	            //     ,      
	            if (week == Calendar.SATURDAY) { 
	                System.out.println(); 
	            } 
	            //       ,         
	            now.add(Calendar.DAY_OF_MONTH, 1); 
	            //            
	            week = now.get(Calendar.DAY_OF_WEEK);  
	        }
	    }
	    
}

좋은 웹페이지 즐겨찾기