728x90
반응형

calendar 출력

public static void main(String[] args) {
	private final char[] DAY_OF_WEEK = {'일', '월', '화', '수', '목', '금', '토'};
    
//	Calendar cal = new Calendar();  //abstract클래스 이기에 new로 만들수 없음
	Calendar cal1 = Calendar.getInstance();  //출력결과는 더보기에서 확인
	Calendar cal2 = new GregorianCalendar(); //출력결과는 더보기에서 확인
	
	System.out.println(cal1);  //1970.1.1 00:00:00.000 기준으로 쌓여온 밀리초를 계산 그 이전이라면 음수(unix second, epoch second)
	System.out.println(cal2);
	
	System.out.println("year : "+cal1.get(Calendar.YEAR));  //상수를 쓰는 형태
	System.out.println("year : "+cal1.get(1));  //위와 똑같은 결과이지만 의도가 명확히 드러나지 않아 가독성 낮음
	System.out.println("month : "+(cal1.get(Calendar.MONTH)+1));  
	System.out.println("date : "+cal1.get(Calendar.DATE));  
	System.out.println("dayofweek : "+cal1.get(Calendar.DAY_OF_WEEK));  
	System.out.println("dayofweek : "+DAY_OF_WEEK[cal1.get(Calendar.DAY_OF_WEEK)-1]);  
	
	System.out.println("am/pm : "+(cal1.get(Calendar.AM_PM)==0?"오전":"오후"));
	System.out.println("hour : "+cal1.get(Calendar.HOUR_OF_DAY));
	System.out.println("min : "+cal1.get(Calendar.MINUTE));
	System.out.println("sec : "+cal1.get(Calendar.SECOND));
	
	System.out.println("unix second : "+cal1.getTimeInMillis());
	
	System.out.println("마지막 날 : "+cal1.getActualMaximum(Calendar.DATE));
}

>

 

더보기

java.util.GregorianCalendar[time=1586441607817,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Asia/Seoul",offset=32400000,dstSavings=0,useDaylight=false,transitions=22,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2020,MONTH=3,WEEK_OF_YEAR=15,WEEK_OF_MONTH=2,DAY_OF_MONTH=9,DAY_OF_YEAR=100,DAY_OF_WEEK=5,DAY_OF_WEEK_IN_MONTH=2,AM_PM=1,HOUR=11,HOUR_OF_DAY=23,MINUTE=13,SECOND=27,MILLISECOND=817,ZONE_OFFSET=32400000,DST_OFFSET=0]

java.util.GregorianCalendar[time=1586441607830,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Asia/Seoul",offset=32400000,dstSavings=0,useDaylight=false,transitions=22,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2020,MONTH=3,WEEK_OF_YEAR=15,WEEK_OF_MONTH=2,DAY_OF_MONTH=9,DAY_OF_YEAR=100,DAY_OF_WEEK=5,DAY_OF_WEEK_IN_MONTH=2,AM_PM=1,HOUR=11,HOUR_OF_DAY=23,MINUTE=13,SECOND=27,MILLISECOND=830,ZONE_OFFSET=32400000,DST_OFFSET=0] 

year : 2020 
year : 2020 
month : 4 
date : 9 
dayofweek : 5 
dayofweek : 목 
am/pm : 오후 
hour : 23 
min : 13 
sec : 27 
unix second : 1586441607817 
마지막 날 : 30

반응형
복사했습니다!